Skip to content

Commit 1d64fb3

Browse files
committed
minor #2803 [CI] Re-add PHP-CS-Fixer (Kocal)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [CI] Re-add PHP-CS-Fixer | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Update/add documentation as required (we can help!) - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Follow #2802, #2074, #2014 and more. I feel like Fabbot **only runs on modified files** for a given PR, but sometimes it does not really help (e.g.: if you untouched files contain old references to a deleted class). This behavior is understandable for symfony/symfony, which contains a tons of code and is super active, but that's not the case symfony/ux, we have very less code and less activity. **EDIT:** Well, I'm still not sure... PHP-CS-Fixer is showing me fixes for `src/LiveComponent/src/Util/TypeHelper.php`, added in #2778, but it was totally ignored by Fabbot... 😫 So, I suggest to re-add PHP-CS-Fixer run in the CI to ensure all files are correctly CS-fixed. Commits ------- 1ab48b6 [CI] Re-add PHP-CS-Fixer
2 parents c68ee12 + 1ab48b6 commit 1d64fb3

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

.github/workflows/code-quality.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ jobs:
2929
- run: yarn --immutable
3030
- run: yarn ci
3131

32+
coding-style-php:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: '8.1'
39+
- run: composer install
40+
- name: php-cs-fixer
41+
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff
42+
3243
phpstan:
3344
name: PHPStan
3445
runs-on: ubuntu-latest

src/LiveComponent/src/LiveComponentHydrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
2424
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2525
use Symfony\Component\TypeInfo\Type;
26-
use Symfony\Component\TypeInfo\TypeIdentifier;
2726
use Symfony\Component\TypeInfo\Type\CollectionType;
2827
use Symfony\Component\TypeInfo\Type\ObjectType;
2928
use Symfony\Component\TypeInfo\Type\WrappingTypeInterface;
29+
use Symfony\Component\TypeInfo\TypeIdentifier;
3030
use Symfony\Component\Uid\AbstractUid;
3131
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
3232
use Symfony\UX\LiveComponent\Attribute\LiveProp;

src/LiveComponent/src/Util/TypeHelper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public static function accepts(Type $type, mixed $value): bool
5858
foreach ($value as $key => $itemValue) {
5959
$valueType = $type->getShape()[$key]['type'] ?? false;
6060

61-
if ($valueType && !TypeHelper::accepts($valueType, $itemValue)) {
61+
if ($valueType && !self::accepts($valueType, $itemValue)) {
6262
return false;
6363
}
6464

65-
if (!$valueType && ($type->isSealed() || !TypeHelper::accepts($type->getExtraKeyType(), $key) || !TypeHelper::accepts($type->getExtraValueType(), $itemValue))) {
65+
if (!$valueType && ($type->isSealed() || !self::accepts($type->getExtraKeyType(), $key) || !self::accepts($type->getExtraValueType(), $itemValue))) {
6666
return false;
6767
}
6868
}
@@ -73,6 +73,7 @@ public static function accepts(Type $type, mixed $value): bool
7373
// Also supports EnumType and BackedEnumType
7474
if ($type instanceof Type\ObjectType) {
7575
$className = $type->getClassName();
76+
7677
return $value instanceof $className;
7778
}
7879

@@ -110,7 +111,7 @@ public static function accepts(Type $type, mixed $value): bool
110111
if (is_iterable($value)) {
111112
foreach ($value as $k => $v) {
112113
// key or value do not match
113-
if (!TypeHelper::accepts($keyType, $k) || !TypeHelper::accepts($valueType, $v)) {
114+
if (!self::accepts($keyType, $k) || !self::accepts($valueType, $v)) {
114115
return false;
115116
}
116117
}

src/Map/src/Polygon.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
final class Polygon implements Element
2222
{
2323
/**
24-
* @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.
24+
* @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
2525
* @param array<string, mixed> $extra Extra data, can be used by the developer to store additional information and use them later JavaScript side
2626
*/
2727
public function __construct(
@@ -76,7 +76,7 @@ public static function fromArray(array $polygon): self
7676

7777
$polygon['points'] = isset($polygon['points'][0]['lat'], $polygon['points'][0]['lng'])
7878
? array_map(Point::fromArray(...), $polygon['points'])
79-
: array_map(fn(array $points) => array_map(Point::fromArray(...), $points), $polygon['points']);
79+
: array_map(fn (array $points) => array_map(Point::fromArray(...), $points), $polygon['points']);
8080

8181
if (isset($polygon['infoWindow'])) {
8282
$polygon['infoWindow'] = InfoWindow::fromArray($polygon['infoWindow']);

src/Toolkit/src/File/ComponentMeta.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ final class ComponentMeta
2424
{
2525
public static function fromJson(string $json): self
2626
{
27-
$data = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
27+
$data = json_decode($json, true, flags: \JSON_THROW_ON_ERROR);
2828
unset($data['$schema']);
2929

3030
$dependencies = [];
3131
foreach ($data['dependencies'] ?? [] as $i => $dependency) {
3232
if (!isset($dependency['type'])) {
33-
throw new \InvalidArgumentException(sprintf('The dependency type is missing for dependency #%d, add "type" key.', $i));
33+
throw new \InvalidArgumentException(\sprintf('The dependency type is missing for dependency #%d, add "type" key.', $i));
3434
}
3535

3636
if ('php' === $dependency['type']) {
37-
$package = $dependency['package'] ?? throw new \InvalidArgumentException(sprintf('The package name is missing for dependency #%d.', $i));
37+
$package = $dependency['package'] ?? throw new \InvalidArgumentException(\sprintf('The package name is missing for dependency #%d.', $i));
3838
if (str_contains($package, ':')) {
3939
[$name, $version] = explode(':', $package, 2);
4040
$dependencies[] = new PhpPackageDependency($name, new Version($version));
@@ -60,7 +60,7 @@ public static function fromJson(string $json): self
6060
* @param list<DependencyInterface> $dependencies
6161
*/
6262
private function __construct(
63-
public readonly array $dependencies
63+
public readonly array $dependencies,
6464
) {
6565
}
6666
}

src/Toolkit/src/Kit/KitSynchronizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ private function synchronizeComponents(Kit $kit): void
7575

7676
$meta = null;
7777
if ($this->filesystem->exists($metaJsonFile = Path::join($file->getPath(), str_replace('.html.twig', '.meta.json', $file->getBasename())))) {
78-
$metaJson = file_get_contents($metaJsonFile) ?: throw new \RuntimeException(sprintf('Unable to get contents from file "%s".', $metaJsonFile));
78+
$metaJson = file_get_contents($metaJsonFile) ?: throw new \RuntimeException(\sprintf('Unable to get contents from file "%s".', $metaJsonFile));
7979
try {
8080
$meta = ComponentMeta::fromJson($metaJson);
8181
} catch (\Throwable $e) {
82-
throw new \RuntimeException(sprintf('Unable to parse component "%s" meta from JSON file "%s".', $componentName, $metaJsonFile), previous: $e);
82+
throw new \RuntimeException(\sprintf('Unable to parse component "%s" meta from JSON file "%s".', $componentName, $metaJsonFile), previous: $e);
8383
}
8484
}
8585

@@ -132,7 +132,7 @@ private function resolveComponentDependencies(Kit $kit, Component $component): v
132132
if (!$component->hasDependency(new PhpPackageDependency($package))) {
133133
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));
134134
}
135-
} else if (null === $componentReference = $kit->getComponent($componentReferenceName)) {
135+
} elseif (null === $componentReference = $kit->getComponent($componentReferenceName)) {
136136
throw new \RuntimeException(\sprintf('Component "%s" not found in component "%s" (file "%s")', $componentReferenceName, $component->name, $file->relativePathNameToKit));
137137
} else {
138138
$component->addDependency(new ComponentDependency($componentReference->name));

0 commit comments

Comments
 (0)