Search by

pascalheidmann / mago-jms-serializer

pascalheidmann

Mago analyzer plugin that treats JMS Serializer annotated/attributed properties as externally read and written, avoiding false unused-property / write-only-property findings.

Package info

github.com/pascalheidmann/mago-jms-serializer

pkg:composer/pascalheidmann/mago-jms-serializer

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-09-22 16:24 UTC

This package is auto-updated.

Last update: 2026-10-06 11:54:05 UTC


README

A Mago analyzer plugin that marks JMS Serializer annotated/attributed properties as read and written externally.

JMS populates these properties via reflection at (de)serialization time — never explicitly assigned or read in PHP source — so Mago's native analyzer would otherwise report them as unused-property / write-only-property. This plugin registers a BeforeAnalysisHook that feeds synthetic read/write references into Mago's own reference graph for any property carrying a JMS\Serializer\Annotation\* attribute, so those findings disappear without a baseline entry.

Installation

composer require --dev pascalheidmann/mago-jms-serializer

Configuring the worker

Mago plugins run inside a separate PHP process ("extension host") that Mago starts and talks to over a small protocol — this package ships only the Plugin class, not that process. Your project needs a small worker script and a mago.toml entry pointing at it.

1. Create a worker entry point, e.g. mago/worker.php:

<?php

declare(strict_types=1);

use Mago\JmsSerializerPlugin\JmsPropertyPlugin;
use Mago\Sdk\Extension;
use Mago\Sdk\Worker;

require __DIR__ . '/../vendor/autoload.php';

(new Worker(new Extension(
    identifier: 'my-project/mago-extensions',
    name: 'My Project Mago Extensions',
    version: '1.0.0',
    analyzerPlugins: [new JmsPropertyPlugin()],
)))->run();

2. Register it as an extension host in mago.toml:

[extension-hosts.my-project]
command = ["php", "mago/worker.php"]

3. Verify it's wired up:

vendor/bin/mago extension validate

Scoping the scan (optional)

By default JmsPropertyPlugin scans every class Mago knows about, including everything under vendor/ you've told Mago to include for symbol resolution. For a large codebase that's needless work, since JMS attributes only ever live in your own code. Pass one or more namespace prefixes to restrict the scan:

new JmsPropertyPlugin(namespacePrefixes: ['App\\'])

This is a pure performance knob — it does not change which properties get suppressed, only how many classes the plugin has to look at to find them. On a mid-sized monorepo this cut analysis time from ~13.5s to ~3.5s with identical findings.

Multiple plugins in one worker

If you have other Mago plugins, one worker process can host all of them:

(new Worker(new Extension(
    identifier: 'my-project/mago-extensions',
    name: 'My Project Mago Extensions',
    version: '1.0.0',
    analyzerPlugins: [
        new JmsPropertyPlugin(),
        new SomeOtherPlugin(),
    ],
)))->run();

License

Dual-licensed under MIT or Apache-2.0, at your option — matching Mago itself.