Skip to content

Fix type safety issues reported by Mago static analyzer#159

Merged
msyk merged 2 commits into
msyk:masterfrom
matsuo:fix-mago-analyze-errors
Jul 4, 2026
Merged

Fix type safety issues reported by Mago static analyzer#159
msyk merged 2 commits into
msyk:masterfrom
matsuo:fix-mago-analyze-errors

Conversation

@matsuo

@matsuo matsuo commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

This PR fixes the following issues reported by the latest Mago.

% mago --version
mago 1.42.0
% git log -1 | head -n 1
commit 8aec368db84e19eb8a3701f2c6798fdeb209be3b
% mago --config .mago/mago.toml analyze                    
warning[possibly-false-array-access]: Cannot perform array access on possibly `false` value.
     ┌─ src/Supporting/CommunicationProvider.php:1118:36
     │
1118 │                 && version_compare(curl_version()['version'], '7.71', '>=')) {
     │                                    ^^^^^^^^^^^^^^ The expression might be `false` here.
     │
     = Attempting to read an array index on `false` will result in a runtime error.
     = Help: Ensure the variable holds an array before accessing it, possibly by checking with `is_array()` or `!== false`.

error[docblock-parameter-narrowing]: Docblock type `array<array-key, object>` for parameter `$responseData` drops part of native type `array<array-key, mixed>|object`.
   ┌─ src/Supporting/FileMakerRelation.php:73:33
   │
64 │      * @param array<object> $responseData
   │               ------------- ...but docblock only covers `array<array-key, object>`
   ·
73 │     public function __construct(array|object           $responseData,
   │                                 ^^^^^^^^^^^^ Native type accepts `array<array-key, mixed>|object`, including `object`...
   │
   = Callers can still pass values of the excluded branches.
   = The docblock tells the analyzer those branches are impossible.
   = Narrowing checks can then collapse to `never` in the body.
   = Help: Widen the docblock to `array<array-key, mixed>|object`, or tighten the native type.

warning[possibly-invalid-array-access]: Cannot perform array access on value of type `object`.
    ┌─ src/Supporting/FileMakerRelation.php:274:17
    │
274 │                 $this->data[$num], $dataInfo, ($this->result == "PORTAL") ? "PORTALRECORD" : "RECORD",
    │                 ^^^^^^^^^^^ The expression might be `object` here.
    │
    = Attempting to use a scalar value as an array will result in a runtime error.
    = Help: Ensure the variable holds an array before accessing it.

warning[possibly-invalid-array-access]: Cannot perform array access on value of type `object`.
    ┌─ src/Supporting/FileMakerRelation.php:554:52
    │
554 │                     $value = new FileMakerRelation($this->data[$this->pointer], $dataInfo, $result,
    │                                                    ^^^^^^^^^^^ The expression might be `object` here.
    │
    = Attempting to use a scalar value as an array will result in a runtime error.
    = Help: Ensure the variable holds an array before accessing it.

error: found 4 issues: 1 error(s), 3 warning(s)

@matsuo matsuo force-pushed the fix-mago-analyze-errors branch from b0a6431 to f84ce5d Compare July 4, 2026 13:14
@matsuo matsuo force-pushed the fix-mago-analyze-errors branch from f84ce5d to 397663b Compare July 4, 2026 13:15
@msyk msyk merged commit e07a0f8 into msyk:master Jul 4, 2026
62 checks passed
@matsuo matsuo deleted the fix-mago-analyze-errors branch July 5, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants