Skip to content

[CI] Re-add PHP-CS-Fixer #2803

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
May 31, 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
11 changes: 11 additions & 0 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use the php-cs-fixer tool provided by shivammathur also

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we won't be able to run it locally, see #617

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, easier to use the installed version so you don't have to duplicate version constraints. I forgot that I don't include in my packages - the ci fixes automatically.

- run: composer install
- name: php-cs-fixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=none

I have a doubt to be honest, it may be automatically set


phpstan:
name: PHPStan
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion src/LiveComponent/src/LiveComponentHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/LiveComponent/src/Util/TypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Map/src/Polygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
final class Polygon implements Element
{
/**
* @param array<Point>|array<array<Point>> $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<Point>|array<array<Point>> $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<string, mixed> $extra Extra data, can be used by the developer to store additional information and use them later JavaScript side
*/
public function __construct(
Expand Down Expand Up @@ -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']);
Expand Down
8 changes: 4 additions & 4 deletions src/Toolkit/src/File/ComponentMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -60,7 +60,7 @@ public static function fromJson(string $json): self
* @param list<DependencyInterface> $dependencies
*/
private function __construct(
public readonly array $dependencies
public readonly array $dependencies,
) {
}
}
6 changes: 3 additions & 3 deletions src/Toolkit/src/Kit/KitSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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));
Expand Down