Skip to content
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
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"symfony/http-kernel": "^7.2"
},
"require-dev": {
"21torr/janus": "^1.4",
"bamarni/composer-bin-plugin": "^1.8",
"21torr/janus": "^1.5.1",
"bamarni/composer-bin-plugin": "^1.8.2",
"doctrine/common": "^3.5",
"roave/security-advisories": "dev-latest",
"phpunit/phpunit": "^12.2.5"
"phpunit/phpunit": "^12.2.5",
"roave/security-advisories": "dev-latest"
},
"autoload": {
"psr-4": {
Expand All @@ -35,6 +35,7 @@
},
"config": {
"allow-plugins": {
"21torr/janus": true,
"bamarni/composer-bin-plugin": true
},
"sort-packages": true
Expand All @@ -48,11 +49,11 @@
"scripts": {
"fix-lint": [
"@composer bin c-norm normalize \"$(pwd)/composer.json\" --indent-style tab --indent-size 1 --ansi",
"vendor-bin/cs-fixer/vendor/bin/php-cs-fixer fix --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi"
"PHP_CS_FIXER_IGNORE_ENV=1 vendor-bin/cs-fixer/vendor/bin/php-cs-fixer fix --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi"
],
"lint": [
"@composer bin c-norm normalize \"$(pwd)/composer.json\" --indent-style tab --indent-size 1 --dry-run --ansi",
"vendor-bin/cs-fixer/vendor/bin/php-cs-fixer check --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi"
"PHP_CS_FIXER_IGNORE_ENV=1 vendor-bin/cs-fixer/vendor/bin/php-cs-fixer check --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi"
],
"test": [
"phpunit",
Expand Down
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
includes:
- vendor/21torr/janus/phpstan/lib.neon

parameters:

# These are temporarily copied here, as normally they should be in the lib.neon of janus.
# However, due to a bug in PHPStan, this currently doesn't work (https://github.com/phpstan/phpstan/issues/12844)
excludePaths:
analyse:
- vendor
analyseAndScan:
- node_modules (?)
- var (?)
- vendor-bin
4 changes: 2 additions & 2 deletions src/Normalizer/SimpleNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* = the object normalizers), as this way we can provide a full path to the invalid element in the JSON.
*
* @readonly
*
* @final
*/
class SimpleNormalizer
Expand All @@ -44,6 +45,7 @@ public function normalize (mixed $value, array $context = []) : mixed

return $normalizedValue;
}

/**
*/
public function normalizeArray (array $array, array $context = []) : array
Expand Down Expand Up @@ -75,8 +77,6 @@ public function normalizeMap (array $array, array $context = []) : array|\stdCla
return $normalizedValue;
}



/**
* The actual normalize logic, that recursively normalizes the value.
* It must never call one of the public methods above and just normalizes the value.
Expand Down
9 changes: 4 additions & 5 deletions src/Normalizer/Validator/ValidJsonVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function ensureValidOnlyJsonTypes (mixed $value) : void
if (null !== $invalidElement)
{
throw new IncompleteNormalizationException(
sprintf(
\sprintf(
"Found a JSON-incompatible value when normalizing. Found '%s' at path '%s', but expected only scalars, arrays and empty objects.",
get_debug_type($invalidElement->value),
implode(".", $invalidElement->path),
Expand All @@ -30,12 +30,11 @@ public function ensureValidOnlyJsonTypes (mixed $value) : void
}
}


/**
* Searches through the value and looks for anything that isn't valid JSON
* (scalars, arrays or empty objects).
*
* @return InvalidJsonElement|null Returns null if everything is valid, otherwise the invalid value.
* @return InvalidJsonElement|null returns null if everything is valid, otherwise the invalid value
*/
private function findInvalidJsonElement (mixed $value, array $path = ["$"]) : ?InvalidJsonElement
{
Expand All @@ -46,14 +45,14 @@ private function findInvalidJsonElement (mixed $value, array $path = ["$"]) : ?I
}

// only empty stdClass objects are allowed (as they are used to serialize to `{}`)
if (is_object($value))
if (\is_object($value))
{
return $value instanceof \stdClass && [] === get_object_vars($value)
? null
: new InvalidJsonElement($value, $path);
}

if (is_array($value))
if (\is_array($value))
{
foreach ($value as $key => $item)
{
Expand Down
20 changes: 9 additions & 11 deletions tests/Normalizer/SimpleNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
namespace Tests\Torr\SimpleNormalizer\Normalizer;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Tests\Torr\SimpleNormalizer\Fixture\DummyVO;
use Torr\SimpleNormalizer\Exception\IncompleteNormalizationException;
use Torr\SimpleNormalizer\Normalizer\SimpleNormalizer;
use PHPUnit\Framework\TestCase;
use Torr\SimpleNormalizer\Normalizer\SimpleObjectNormalizerInterface;
use Torr\SimpleNormalizer\Normalizer\Validator\ValidJsonVerifier;

class SimpleNormalizerTest extends TestCase
/**
* @internal
*/
final class SimpleNormalizerTest extends TestCase
{
/**
*
Expand Down Expand Up @@ -40,7 +43,7 @@ public function testJsonVerifierEnabled (callable $call) : void
$verifier = $this->createMock(ValidJsonVerifier::class);

$verifier
->expects($this->once())
->expects(self::once())
->method('ensureValidOnlyJsonTypes');

$normalizer = new SimpleNormalizer(
Expand All @@ -59,7 +62,6 @@ public function testJsonVerifierEnabled (callable $call) : void
]);
}


/**
*
*/
Expand All @@ -68,7 +70,7 @@ public function testJsonVerifierDisabled () : void
$verifier = $this->createMock(ValidJsonVerifier::class);

$verifier
->expects($this->never())
->expects(self::never())
->method('ensureValidOnlyJsonTypes');

$normalizer = new SimpleNormalizer(
Expand All @@ -83,7 +85,6 @@ public function testJsonVerifierDisabled () : void
self::assertTrue(true); // Just to ensure the test runs without exceptions
}


/**
*
*/
Expand All @@ -100,7 +101,6 @@ public function testInvalidNormalizer () : void
$normalizer->normalize(new DummyVO(42));
}


/**
*
*/
Expand All @@ -124,15 +124,13 @@ public function testInvalidNestedNormalizer () : void
]);
}


/**
*
* @return ServiceLocator<mixed>
*/
private function createNormalizerObjectNormalizers (mixed $returnValue) : ServiceLocator
{
return new ServiceLocator([
DummyVO::class => static fn () => new readonly class ($returnValue) implements SimpleObjectNormalizerInterface
{
DummyVO::class => static fn () => new readonly class($returnValue) implements SimpleObjectNormalizerInterface {
public function __construct (
private mixed $returnValue,
) {}
Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/c-norm/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require-dev": {
"ergebnis/composer-normalize": "^2.42",
"ergebnis/composer-normalize": "^2.47",
"roave/security-advisories": "dev-latest"
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/cs-fixer/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require-dev": {
"21torr/php-cs-fixer": "^1.1.1",
"21torr/php-cs-fixer": "^1.1.5",
"roave/security-advisories": "dev-latest"
}
}
14 changes: 7 additions & 7 deletions vendor-bin/phpstan/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"php": "^8.3"
},
"require-dev": {
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpstan/phpstan-doctrine": "^1.4",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-symfony": "^1.4",
"phpstan/extension-installer": "^1.4.2",
"phpstan/phpstan": "^2.1.11",
"phpstan/phpstan-deprecation-rules": "^2.0.1",
"phpstan/phpstan-doctrine": "^2.0.2",
"phpstan/phpstan-phpunit": "^2.0.6",
"phpstan/phpstan-symfony": "^2.0.4",
"roave/security-advisories": "dev-latest",
"staabm/phpstan-todo-by": "^0.1.25"
"staabm/phpstan-todo-by": "^0.2"
},
"config": {
"sort-packages": true,
Expand Down