Skip to content

Commit 6e87ecd

Browse files
committed
[Turbo] Upgrading and fixing phpstan & CI
1 parent 16d035d commit 6e87ecd

30 files changed

+369
-391
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,6 @@ jobs:
147147
- name: Translator Tests
148148
run: php vendor/bin/simple-phpunit
149149
working-directory: src/Translator
150-
151-
- name: StimulusBundle Dependencies
152-
uses: ramsey/composer-install@v2
153-
with:
154-
working-directory: src/StimulusBundle
155-
dependency-versions: lowest
156-
- name: StimulusBundle Tests
157-
working-directory: src/StimulusBundle
158-
run: php vendor/bin/simple-phpunit
159-
160150
tests-php-high-deps:
161151
runs-on: ubuntu-latest
162152
steps:

src/Autocomplete/src/Doctrine/EntitySearchUtil.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public function addSearchClause(QueryBuilder $queryBuilder, string $query, strin
9999

100100
// this complex condition is needed to avoid issues on PostgreSQL databases
101101
if (
102-
($isSmallIntegerProperty && $isSmallIntegerQuery) ||
103-
($isIntegerProperty && $isIntegerQuery) ||
104-
($isNumericProperty && $isNumericQuery)
102+
($isSmallIntegerProperty && $isSmallIntegerQuery)
103+
|| ($isIntegerProperty && $isIntegerQuery)
104+
|| ($isNumericProperty && $isNumericQuery)
105105
) {
106106
$expressions[] = $queryBuilder->expr()->eq(sprintf('%s.%s', $entityName, $propertyName), ':query_for_numbers');
107107
$queryBuilder->setParameter('query_for_numbers', $dqlParameters['numeric_query']);

src/Autocomplete/src/Form/ParentEntityAutocompleteType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ public function __construct(
3434
public function buildForm(FormBuilderInterface $builder, array $options)
3535
{
3636
$formType = $builder->getType()->getInnerType();
37-
$attribute = AsEntityAutocompleteField::getInstance(\get_class($formType));
37+
$attribute = AsEntityAutocompleteField::getInstance($formType::class);
3838

3939
if (!$attribute && empty($options['autocomplete_url'])) {
40-
throw new \LogicException(sprintf('You must either provide your own autocomplete_url, or add #[AsEntityAutocompleteField] attribute to %s.', \get_class($formType)));
40+
throw new \LogicException(sprintf('You must either provide your own autocomplete_url, or add #[AsEntityAutocompleteField] attribute to %s.', $formType::class));
4141
}
4242

4343
// Use the provided URL, or auto-generate from the provided alias
4444
$autocompleteUrl = $options['autocomplete_url'] ?? $this->urlGenerator->generate($attribute->getRoute(), [
45-
'alias' => $attribute->getAlias() ?: AsEntityAutocompleteField::shortName(\get_class($formType)),
45+
'alias' => $attribute->getAlias() ?: AsEntityAutocompleteField::shortName($formType::class),
4646
]);
4747

4848
$builder

src/LiveComponent/src/Attribute/AsLiveComponent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
final class AsLiveComponent extends AsTwigComponent
2323
{
2424
public function __construct(
25-
?string $name = null,
26-
?string $template = null,
25+
string $name = null,
26+
string $template = null,
2727
private ?string $defaultAction = null,
2828
bool $exposePublicProps = true,
2929
string $attributesVar = 'attributes',

src/LiveComponent/src/Attribute/LiveProp.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ final class LiveProp
6767
*/
6868
public function __construct(
6969
bool|array $writable = false,
70-
?string $hydrateWith = null,
71-
?string $dehydrateWith = null,
70+
string $hydrateWith = null,
71+
string $dehydrateWith = null,
7272
bool $useSerializerForHydration = false,
7373
array $serializationContext = [],
74-
?string $fieldName = null,
75-
?string $format = null,
74+
string $fieldName = null,
75+
string $format = null,
7676
bool $updateFromParent = false
7777
) {
7878
$this->writable = $writable;

src/LiveComponent/src/EventListener/LiveComponentSubscriber.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ public function onKernelRequest(RequestEvent $event): void
110110
}
111111

112112
if (
113-
$this->container->has(CsrfTokenManagerInterface::class) &&
114-
$metadata->get('csrf') &&
115-
!$this->container->get(CsrfTokenManagerInterface::class)->isTokenValid(new CsrfToken(LiveControllerAttributesCreator::getCsrfTokeName($componentName), $request->headers->get('X-CSRF-TOKEN')))) {
113+
$this->container->has(CsrfTokenManagerInterface::class)
114+
&& $metadata->get('csrf')
115+
&& !$this->container->get(CsrfTokenManagerInterface::class)->isTokenValid(new CsrfToken(LiveControllerAttributesCreator::getCsrfTokeName($componentName), $request->headers->get('X-CSRF-TOKEN')))) {
116116
throw new BadRequestHttpException('Invalid CSRF token.');
117117
}
118118

@@ -161,7 +161,7 @@ public function onKernelController(ControllerEvent $event): void
161161
}
162162

163163
if (!$request->attributes->get('_component_default_action', false) && !AsLiveComponent::isActionAllowed($component, $action)) {
164-
throw new NotFoundHttpException(sprintf('The action "%s" either doesn\'t exist or is not allowed in "%s". Make sure it exist and has the LiveAction attribute above it.', $action, \get_class($component)));
164+
throw new NotFoundHttpException(sprintf('The action "%s" either doesn\'t exist or is not allowed in "%s". Make sure it exist and has the LiveAction attribute above it.', $action, $component::class));
165165
}
166166

167167
/*

src/LiveComponent/src/Hydration/DoctrineEntityHydrationExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function hydrate(mixed $value, string $className): ?object
5454
public function dehydrate(object $object): mixed
5555
{
5656
$id = $this
57-
->objectManagerFor($class = \get_class($object))
57+
->objectManagerFor($class = $object::class)
5858
->getClassMetadata($class)
5959
->getIdentifierValues($object)
6060
;

src/LiveComponent/src/LiveComponentHydrator.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function dehydrate(object $component, ComponentAttributes $attributes, Li
6464
$frontendName = $propMetadata->calculateFieldName($component, $propertyName);
6565

6666
if (isset($takenFrontendPropertyNames[$frontendName])) {
67-
$message = sprintf('The field name "%s" cannot be used by multiple LiveProp properties in a component. Currently, both "%s" and "%s" are trying to use it in "%s".', $frontendName, $takenFrontendPropertyNames[$frontendName], $propertyName, \get_class($component));
67+
$message = sprintf('The field name "%s" cannot be used by multiple LiveProp properties in a component. Currently, both "%s" and "%s" are trying to use it in "%s".', $frontendName, $takenFrontendPropertyNames[$frontendName], $propertyName, $component::class);
6868

6969
if ($frontendName === $takenFrontendPropertyNames[$frontendName] || $frontendName === $propertyName) {
7070
$message .= sprintf(' Try adding LiveProp(fieldName="somethingElse") for the "%s" property to avoid this.', $frontendName);
@@ -79,7 +79,7 @@ public function dehydrate(object $component, ComponentAttributes $attributes, Li
7979
try {
8080
$rawPropertyValue = $this->propertyAccessor->getValue($component, $propertyName);
8181
} catch (UninitializedPropertyException $exception) {
82-
throw new \LogicException(sprintf('The "%s" property on the "%s" component is uninitialized. Did you forget to pass this into the component?', $propertyName, \get_class($component)), 0, $exception);
82+
throw new \LogicException(sprintf('The "%s" property on the "%s" component is uninitialized. Did you forget to pass this into the component?', $propertyName, $component::class), 0, $exception);
8383
}
8484

8585
$dehydratedValue = $this->dehydrateValue($rawPropertyValue, $propMetadata, $component);
@@ -95,14 +95,14 @@ public function dehydrate(object $component, ComponentAttributes $attributes, Li
9595
$this->adjustPropertyPathForData($rawPropertyValue, $path)
9696
);
9797
} catch (NoSuchPropertyException $e) {
98-
throw new \LogicException(sprintf('The writable path "%s" does not exist on the "%s" property of the "%s" component.', $path, $propertyName, \get_class($component)), 0, $e);
98+
throw new \LogicException(sprintf('The writable path "%s" does not exist on the "%s" property of the "%s" component.', $path, $propertyName, $component::class), 0, $e);
9999
} catch (PropertyAccessExceptionInterface $e) {
100-
throw new \LogicException(sprintf('The writable path "%s" on the "%s" property of the "%s" component could not be read: %s', $path, $propertyName, \get_class($component), $e->getMessage()), 0, $e);
100+
throw new \LogicException(sprintf('The writable path "%s" on the "%s" property of the "%s" component could not be read: %s', $path, $propertyName, $component::class, $e->getMessage()), 0, $e);
101101
}
102102

103103
// TODO: maybe we allow support the same types as LiveProps later
104104
if (!$this->isValueValidDehydratedValue($pathValue)) {
105-
throw new \LogicException(sprintf('The writable path "%s" on the "%s" property of the "%s" component must be a scalar or array of scalars.', $path, $propertyName, \get_class($component)));
105+
throw new \LogicException(sprintf('The writable path "%s" on the "%s" property of the "%s" component must be a scalar or array of scalars.', $path, $propertyName, $component::class));
106106
}
107107

108108
$dehydratedProps->addNestedProp($frontendName, $path, $pathValue);
@@ -161,7 +161,7 @@ public function hydrate(object $component, array $props, array $updatedProps, Li
161161
| 2) Set ORIGINAL "writable paths" data for this LiveProp.
162162
| (which may represent data that was updated on a previous request)
163163
*/
164-
$originalWritablePaths = $this->calculateWritablePaths($propMetadata, $propertyValue, $dehydratedOriginalProps, $frontendName, \get_class($component));
164+
$originalWritablePaths = $this->calculateWritablePaths($propMetadata, $propertyValue, $dehydratedOriginalProps, $frontendName, $component::class);
165165
$propertyValue = $this->setWritablePaths(
166166
$originalWritablePaths,
167167
$frontendName,
@@ -177,7 +177,7 @@ public function hydrate(object $component, array $props, array $updatedProps, Li
177177
*/
178178
if ($dehydratedUpdatedProps->hasPropValue($frontendName)) {
179179
if (!$propMetadata->isIdentityWritable()) {
180-
throw new HydrationException(sprintf('The model "%s" was sent for update, but it is not writable. Try adding "writable: true" to the $%s property in %s.', $frontendName, $propMetadata->getName(), \get_class($component)));
180+
throw new HydrationException(sprintf('The model "%s" was sent for update, but it is not writable. Try adding "writable: true" to the $%s property in %s.', $frontendName, $propMetadata->getName(), $component::class));
181181
}
182182
try {
183183
$propertyValue = $this->hydrateValue(
@@ -193,7 +193,7 @@ public function hydrate(object $component, array $props, array $updatedProps, Li
193193
/*
194194
| 4) Set UPDATED "writable paths" data for this LiveProp.
195195
*/
196-
$updatedWritablePaths = $this->calculateWritablePaths($propMetadata, $propertyValue, $dehydratedUpdatedProps, $frontendName, \get_class($component));
196+
$updatedWritablePaths = $this->calculateWritablePaths($propMetadata, $propertyValue, $dehydratedUpdatedProps, $frontendName, $component::class);
197197
$propertyValue = $this->setWritablePaths(
198198
$updatedWritablePaths,
199199
$frontendName,
@@ -326,7 +326,7 @@ private function dehydrateValue(mixed $value, LivePropMetadata $propMetadata, ob
326326
{
327327
if ($method = $propMetadata->dehydrateMethod()) {
328328
if (!method_exists($component, $method)) {
329-
throw new \LogicException(sprintf('The "%s" component has a dehydrateMethod of "%s" but the method does not exist.', \get_class($component), $method));
329+
throw new \LogicException(sprintf('The "%s" component has a dehydrateMethod of "%s" but the method does not exist.', $component::class, $method));
330330
}
331331

332332
return $component->$method($value);
@@ -345,35 +345,35 @@ private function dehydrateValue(mixed $value, LivePropMetadata $propMetadata, ob
345345
$collectionClass = $propMetadata->collectionValueType()->getClassName();
346346
foreach ($value as $key => $objectItem) {
347347
if (!$objectItem instanceof $collectionClass) {
348-
throw new \LogicException(sprintf('The LiveProp "%s" on component "%s" is an array. We determined the array is full of %s objects, but at least on key had a different value of %s', $propMetadata->getName(), \get_class($component), $collectionClass, get_debug_type($objectItem)));
348+
throw new \LogicException(sprintf('The LiveProp "%s" on component "%s" is an array. We determined the array is full of %s objects, but at least on key had a different value of %s', $propMetadata->getName(), $component::class, $collectionClass, get_debug_type($objectItem)));
349349
}
350350

351-
$value[$key] = $this->dehydrateObjectValue($objectItem, $collectionClass, $propMetadata->getFormat(), \get_class($component), sprintf('%s.%s', $propMetadata->getName(), $key));
351+
$value[$key] = $this->dehydrateObjectValue($objectItem, $collectionClass, $propMetadata->getFormat(), $component::class, sprintf('%s.%s', $propMetadata->getName(), $key));
352352
}
353353
}
354354

355355
if (!$this->isValueValidDehydratedValue($value)) {
356356
$badKeys = $this->getNonScalarKeys($value, $propMetadata->getName());
357357
$badKeysText = implode(', ', array_map(fn ($key) => sprintf('%s: %s', $key, $badKeys[$key]), array_keys($badKeys)));
358358

359-
throw new \LogicException(sprintf('The LiveProp "%s" on component "%s" is an array, but it contains one or more keys that are not scalars: %s', $propMetadata->getName(), \get_class($component), $badKeysText));
359+
throw new \LogicException(sprintf('The LiveProp "%s" on component "%s" is an array, but it contains one or more keys that are not scalars: %s', $propMetadata->getName(), $component::class, $badKeysText));
360360
}
361361

362362
return $value;
363363
}
364364

365365
if (!\is_object($value)) {
366-
throw new \LogicException(sprintf('Unable to dehydrate value of type "%s" for property "%s" on component "%s". Change this to a simpler type of an object that can be dehydrated. Or set the hydrateWith/dehydrateWith options in LiveProp or set "useSerializerForHydration: true" on the LiveProp to use the serializer.', get_debug_type($value), $propMetadata->getName(), \get_class($component)));
366+
throw new \LogicException(sprintf('Unable to dehydrate value of type "%s" for property "%s" on component "%s". Change this to a simpler type of an object that can be dehydrated. Or set the hydrateWith/dehydrateWith options in LiveProp or set "useSerializerForHydration: true" on the LiveProp to use the serializer.', get_debug_type($value), $propMetadata->getName(), $component::class));
367367
}
368368

369369
if (!$propMetadata->getType() || $propMetadata->isBuiltIn()) {
370-
throw new \LogicException(sprintf('The "%s" property on component "%s" is missing its property-type. Add the "%s" type so the object can be hydrated later.', $propMetadata->getName(), \get_class($component), \get_class($value)));
370+
throw new \LogicException(sprintf('The "%s" property on component "%s" is missing its property-type. Add the "%s" type so the object can be hydrated later.', $propMetadata->getName(), $component::class, $value::class));
371371
}
372372

373373
// at this point, we have an object and can assume $propMetadata->getType()
374374
// is set correctly (needed for hydration later)
375375

376-
return $this->dehydrateObjectValue($value, $propMetadata->getType(), $propMetadata->getFormat(), \get_class($component), $propMetadata->getName());
376+
return $this->dehydrateObjectValue($value, $propMetadata->getType(), $propMetadata->getFormat(), $component::class, $propMetadata->getName());
377377
}
378378

379379
private function dehydrateObjectValue(object $value, string $classType, ?string $dateFormat, string $componentClassForError, string $propertyPathForError): mixed
@@ -392,14 +392,14 @@ private function dehydrateObjectValue(object $value, string $classType, ?string
392392
}
393393
}
394394

395-
throw new \LogicException(sprintf('Unable to dehydrate value of type "%s" for property "%s" on component "%s". Either (1) change this to a simpler value, (2) add the hydrateWith/dehydrateWith options to LiveProp or (3) set "useSerializerForHydration: true" on the LiveProp.', \get_class($value), $propertyPathForError, $componentClassForError));
395+
throw new \LogicException(sprintf('Unable to dehydrate value of type "%s" for property "%s" on component "%s". Either (1) change this to a simpler value, (2) add the hydrateWith/dehydrateWith options to LiveProp or (3) set "useSerializerForHydration: true" on the LiveProp.', $value::class, $propertyPathForError, $componentClassForError));
396396
}
397397

398398
private function hydrateValue(mixed $value, LivePropMetadata $propMetadata, object $component): mixed
399399
{
400400
if ($propMetadata->hydrateMethod()) {
401401
if (!method_exists($component, $propMetadata->hydrateMethod())) {
402-
throw new \LogicException(sprintf('The "%s" component has a hydrateMethod of "%s" but the method does not exist.', \get_class($component), $propMetadata->hydrateMethod()));
402+
throw new \LogicException(sprintf('The "%s" component has a hydrateMethod of "%s" but the method does not exist.', $component::class, $propMetadata->hydrateMethod()));
403403
}
404404

405405
return $component->{$propMetadata->hydrateMethod()}($value);
@@ -412,7 +412,7 @@ private function hydrateValue(mixed $value, LivePropMetadata $propMetadata, obje
412412
if ($propMetadata->collectionValueType() && Type::BUILTIN_TYPE_OBJECT === $propMetadata->collectionValueType()->getBuiltinType()) {
413413
$collectionClass = $propMetadata->collectionValueType()->getClassName();
414414
foreach ($value as $key => $objectItem) {
415-
$value[$key] = $this->hydrateObjectValue($objectItem, $collectionClass, true, \get_class($component), sprintf('%s.%s', $propMetadata->getName(), $key));
415+
$value[$key] = $this->hydrateObjectValue($objectItem, $collectionClass, true, $component::class, sprintf('%s.%s', $propMetadata->getName(), $key));
416416
}
417417
}
418418

@@ -434,7 +434,7 @@ private function hydrateValue(mixed $value, LivePropMetadata $propMetadata, obje
434434
return $value;
435435
}
436436

437-
return $this->hydrateObjectValue($value, $propMetadata->getType(), $propMetadata->allowsNull(), \get_class($component), $propMetadata->getName());
437+
return $this->hydrateObjectValue($value, $propMetadata->getType(), $propMetadata->allowsNull(), $component::class, $propMetadata->getName());
438438
}
439439

440440
private function hydrateObjectValue(mixed $value, string $className, bool $allowsNull, string $componentClassForError, string $propertyPathForError): ?object

src/LiveComponent/src/Twig/DeterministicTwigIdCalculator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private function guessTemplateInfo(): array
8484
foreach ($backtrace as $trace) {
8585
if (isset($trace['object']) && $trace['object'] instanceof Template) {
8686
$currentClass = \get_class($trace['object']);
87-
$isEmbedContainer = null === $templateClass ? false : 0 === strpos($templateClass, $currentClass);
87+
$isEmbedContainer = null === $templateClass ? false : str_starts_with($templateClass, $currentClass);
8888
// START CHANGE
8989
// if statement not needed
9090
// if (null === $this->name || ($this->name == $trace['object']->getTemplateName() && !$isEmbedContainer)) {

0 commit comments

Comments
 (0)