Skip to content

Add modification type in json output #932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Resources/errors.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"type": "null"
}
]
},
"modificationType": {
"type": "string"
}
},
"required": [
Expand Down
5 changes: 5 additions & 0 deletions src/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
}

/** @psalm-pure */
public static function added(string $description, bool $isBcBreak = true): self

Check warning on line 30 in src/Change.php

View workflow job for this annotation

GitHub Actions / QA Checks (Infection (PCOV) [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-...

Escaped Mutant for Mutator "TrueValue": @@ @@ { } /** @psalm-pure */ - public static function added(string $description, bool $isBcBreak = true): self + public static function added(string $description, bool $isBcBreak = false): self { return new self(self::ADDED, $description, $isBcBreak); }
{
return new self(self::ADDED, $description, $isBcBreak);
}

/** @psalm-pure */
public static function changed(string $description, bool $isBcBreak = true): self

Check warning on line 36 in src/Change.php

View workflow job for this annotation

GitHub Actions / QA Checks (Infection (PCOV) [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-...

Escaped Mutant for Mutator "TrueValue": @@ @@ return new self(self::ADDED, $description, $isBcBreak); } /** @psalm-pure */ - public static function changed(string $description, bool $isBcBreak = true): self + public static function changed(string $description, bool $isBcBreak = false): self { return new self(self::CHANGED, $description, $isBcBreak); }
{
return new self(self::CHANGED, $description, $isBcBreak);
}

/** @psalm-pure */
public static function removed(string $description, bool $isBcBreak = true): self

Check warning on line 42 in src/Change.php

View workflow job for this annotation

GitHub Actions / QA Checks (Infection (PCOV) [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-...

Escaped Mutant for Mutator "TrueValue": @@ @@ return new self(self::CHANGED, $description, $isBcBreak); } /** @psalm-pure */ - public static function removed(string $description, bool $isBcBreak = true): self + public static function removed(string $description, bool $isBcBreak = false): self { return new self(self::REMOVED, $description, $isBcBreak); }
{
return new self(self::REMOVED, $description, $isBcBreak);
}
Expand Down Expand Up @@ -71,6 +71,11 @@
return $this->modificationType === self::SKIPPED;
}

public function getModificationType(): string
{
return $this->modificationType;
}

/** @internal */
public function withFilePositionsIfNotAlreadySet(
string|null $file,
Expand Down
1 change: 1 addition & 0 deletions src/Formatter/JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function write(Changes $changes): void
'path' => $change->file === null ? null : Str\replace($change->file, $basePath, ''),
'line' => $change->line,
'column' => $change->column,
'modificationType' => $change->getModificationType(),
];
}

Expand Down
16 changes: 8 additions & 8 deletions test/unit/Formatter/JsonFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public function testWrite(): void

$expected = [
'errors' => [
['description' => 'foo', 'path' => null, 'line' => null, 'column' => null],
['description' => 'bar', 'path' => null, 'line' => null, 'column' => null],
['description' => 'baz', 'path' => 'baz-file.php', 'line' => null, 'column' => null],
['description' => 'tab', 'path' => 'tab-file.php', 'line' => 5, 'column' => null],
['description' => 'taz', 'path' => 'taz-file.php', 'line' => 6, 'column' => 15],
['description' => 'tar', 'path' => 'tar-file.php', 'line' => -1, 'column' => -1],
['description' => 'file-in-checked-out-dir', 'path' => 'subpath/file-in-checked-out-dir.php', 'line' => 10, 'column' => 20],
['description' => 'foo', 'path' => null, 'line' => null, 'column' => null, 'modificationType' => 'removed'],
['description' => 'bar', 'path' => null, 'line' => null, 'column' => null, 'modificationType' => 'added'],
['description' => 'baz', 'path' => 'baz-file.php', 'line' => null, 'column' => null, 'modificationType' => 'changed'],
['description' => 'tab', 'path' => 'tab-file.php', 'line' => 5, 'column' => null, 'modificationType' => 'changed'],
['description' => 'taz', 'path' => 'taz-file.php', 'line' => 6, 'column' => 15, 'modificationType' => 'changed'],
['description' => 'tar', 'path' => 'tar-file.php', 'line' => -1, 'column' => -1, 'modificationType' => 'changed'],
['description' => 'file-in-checked-out-dir', 'path' => 'subpath/file-in-checked-out-dir.php', 'line' => 10, 'column' => 20, 'modificationType' => 'changed'],
],
];

Expand All @@ -86,7 +86,7 @@ public function testWrite(): void

self::assertJsonStringEqualsJsonString(
<<<'OUTPUT'
{"errors":[{"description":"foo","path":null,"line":null,"column":null},{"description":"bar","path":null,"line":null,"column":null},{"description":"baz","path":"baz-file.php","line":null,"column":null},{"description":"tab","path":"tab-file.php","line":5,"column":null},{"description":"taz","path":"taz-file.php","line":6,"column":15},{"description":"tar","path":"tar-file.php","line":-1,"column":-1},{"description":"file-in-checked-out-dir","path":"subpath\/file-in-checked-out-dir.php","line":10,"column":20}]}
{"errors":[{"description":"foo","path":null,"line":null,"column":null,"modificationType":"removed"},{"description":"bar","path":null,"line":null,"column":null,"modificationType":"added"},{"description":"baz","path":"baz-file.php","line":null,"column":null,"modificationType":"changed"},{"description":"tab","path":"tab-file.php","line":5,"column":null,"modificationType":"changed"},{"description":"taz","path":"taz-file.php","line":6,"column":15,"modificationType":"changed"},{"description":"tar","path":"tar-file.php","line":-1,"column":-1,"modificationType":"changed"},{"description":"file-in-checked-out-dir","path":"subpath\/file-in-checked-out-dir.php","line":10,"column":20,"modificationType":"changed"}]}

OUTPUT
,
Expand Down
Loading