diff --git a/.github/workflows/code-quality.yaml b/.github/workflows/code-quality.yaml index bf9fd03867b..94cfde8462d 100644 --- a/.github/workflows/code-quality.yaml +++ b/.github/workflows/code-quality.yaml @@ -29,6 +29,17 @@ jobs: - run: yarn --immutable - run: yarn ci + coding-style-php: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + - run: composer install + - name: php-cs-fixer + run: ./vendor/bin/php-cs-fixer fix --dry-run --diff + phpstan: name: PHPStan runs-on: ubuntu-latest diff --git a/src/LiveComponent/src/LiveComponentHydrator.php b/src/LiveComponent/src/LiveComponentHydrator.php index 71aecd31704..9f4af3c31fc 100644 --- a/src/LiveComponent/src/LiveComponentHydrator.php +++ b/src/LiveComponent/src/LiveComponentHydrator.php @@ -23,10 +23,10 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\TypeInfo\Type; -use Symfony\Component\TypeInfo\TypeIdentifier; use Symfony\Component\TypeInfo\Type\CollectionType; use Symfony\Component\TypeInfo\Type\ObjectType; use Symfony\Component\TypeInfo\Type\WrappingTypeInterface; +use Symfony\Component\TypeInfo\TypeIdentifier; use Symfony\Component\Uid\AbstractUid; use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; use Symfony\UX\LiveComponent\Attribute\LiveProp; diff --git a/src/LiveComponent/src/Util/TypeHelper.php b/src/LiveComponent/src/Util/TypeHelper.php index b31ce99b777..6c79151d429 100644 --- a/src/LiveComponent/src/Util/TypeHelper.php +++ b/src/LiveComponent/src/Util/TypeHelper.php @@ -58,11 +58,11 @@ public static function accepts(Type $type, mixed $value): bool foreach ($value as $key => $itemValue) { $valueType = $type->getShape()[$key]['type'] ?? false; - if ($valueType && !TypeHelper::accepts($valueType, $itemValue)) { + if ($valueType && !self::accepts($valueType, $itemValue)) { return false; } - if (!$valueType && ($type->isSealed() || !TypeHelper::accepts($type->getExtraKeyType(), $key) || !TypeHelper::accepts($type->getExtraValueType(), $itemValue))) { + if (!$valueType && ($type->isSealed() || !self::accepts($type->getExtraKeyType(), $key) || !self::accepts($type->getExtraValueType(), $itemValue))) { return false; } } @@ -73,6 +73,7 @@ public static function accepts(Type $type, mixed $value): bool // Also supports EnumType and BackedEnumType if ($type instanceof Type\ObjectType) { $className = $type->getClassName(); + return $value instanceof $className; } @@ -110,7 +111,7 @@ public static function accepts(Type $type, mixed $value): bool if (is_iterable($value)) { foreach ($value as $k => $v) { // key or value do not match - if (!TypeHelper::accepts($keyType, $k) || !TypeHelper::accepts($valueType, $v)) { + if (!self::accepts($keyType, $k) || !self::accepts($valueType, $v)) { return false; } } diff --git a/src/Map/src/Polygon.php b/src/Map/src/Polygon.php index 4eb6747f171..2622634cb2c 100644 --- a/src/Map/src/Polygon.php +++ b/src/Map/src/Polygon.php @@ -21,7 +21,7 @@ final class Polygon implements Element { /** - * @param array|array> $points A list of point representing the polygon, or a list of paths (each path is an array of points) representing a polygon with holes. + * @param array|array> $points a list of point representing the polygon, or a list of paths (each path is an array of points) representing a polygon with holes * @param array $extra Extra data, can be used by the developer to store additional information and use them later JavaScript side */ public function __construct( @@ -76,7 +76,7 @@ public static function fromArray(array $polygon): self $polygon['points'] = isset($polygon['points'][0]['lat'], $polygon['points'][0]['lng']) ? array_map(Point::fromArray(...), $polygon['points']) - : array_map(fn(array $points) => array_map(Point::fromArray(...), $points), $polygon['points']); + : array_map(fn (array $points) => array_map(Point::fromArray(...), $points), $polygon['points']); if (isset($polygon['infoWindow'])) { $polygon['infoWindow'] = InfoWindow::fromArray($polygon['infoWindow']); diff --git a/src/Toolkit/src/File/ComponentMeta.php b/src/Toolkit/src/File/ComponentMeta.php index f57b62240e5..9048ce1dd5d 100644 --- a/src/Toolkit/src/File/ComponentMeta.php +++ b/src/Toolkit/src/File/ComponentMeta.php @@ -24,17 +24,17 @@ final class ComponentMeta { public static function fromJson(string $json): self { - $data = json_decode($json, true, flags: JSON_THROW_ON_ERROR); + $data = json_decode($json, true, flags: \JSON_THROW_ON_ERROR); unset($data['$schema']); $dependencies = []; foreach ($data['dependencies'] ?? [] as $i => $dependency) { if (!isset($dependency['type'])) { - throw new \InvalidArgumentException(sprintf('The dependency type is missing for dependency #%d, add "type" key.', $i)); + throw new \InvalidArgumentException(\sprintf('The dependency type is missing for dependency #%d, add "type" key.', $i)); } if ('php' === $dependency['type']) { - $package = $dependency['package'] ?? throw new \InvalidArgumentException(sprintf('The package name is missing for dependency #%d.', $i)); + $package = $dependency['package'] ?? throw new \InvalidArgumentException(\sprintf('The package name is missing for dependency #%d.', $i)); if (str_contains($package, ':')) { [$name, $version] = explode(':', $package, 2); $dependencies[] = new PhpPackageDependency($name, new Version($version)); @@ -60,7 +60,7 @@ public static function fromJson(string $json): self * @param list $dependencies */ private function __construct( - public readonly array $dependencies + public readonly array $dependencies, ) { } } diff --git a/src/Toolkit/src/Kit/KitSynchronizer.php b/src/Toolkit/src/Kit/KitSynchronizer.php index cb0869efd8d..0aaf95840e6 100644 --- a/src/Toolkit/src/Kit/KitSynchronizer.php +++ b/src/Toolkit/src/Kit/KitSynchronizer.php @@ -75,11 +75,11 @@ private function synchronizeComponents(Kit $kit): void $meta = null; if ($this->filesystem->exists($metaJsonFile = Path::join($file->getPath(), str_replace('.html.twig', '.meta.json', $file->getBasename())))) { - $metaJson = file_get_contents($metaJsonFile) ?: throw new \RuntimeException(sprintf('Unable to get contents from file "%s".', $metaJsonFile)); + $metaJson = file_get_contents($metaJsonFile) ?: throw new \RuntimeException(\sprintf('Unable to get contents from file "%s".', $metaJsonFile)); try { $meta = ComponentMeta::fromJson($metaJson); } catch (\Throwable $e) { - throw new \RuntimeException(sprintf('Unable to parse component "%s" meta from JSON file "%s".', $componentName, $metaJsonFile), previous: $e); + throw new \RuntimeException(\sprintf('Unable to parse component "%s" meta from JSON file "%s".', $componentName, $metaJsonFile), previous: $e); } } @@ -132,7 +132,7 @@ private function resolveComponentDependencies(Kit $kit, Component $component): v if (!$component->hasDependency(new PhpPackageDependency($package))) { throw new \RuntimeException(\sprintf('Component "%s" uses "%s" UX Twig component, but the composer package "%s" is not listed as a dependency in meta file.', $component->name, $componentReferenceName, $package)); } - } else if (null === $componentReference = $kit->getComponent($componentReferenceName)) { + } elseif (null === $componentReference = $kit->getComponent($componentReferenceName)) { throw new \RuntimeException(\sprintf('Component "%s" not found in component "%s" (file "%s")', $componentReferenceName, $component->name, $file->relativePathNameToKit)); } else { $component->addDependency(new ComponentDependency($componentReference->name));