diff --git a/src/CoreBundle/Command/SonataDumpDoctrineMetaCommand.php b/src/CoreBundle/Command/SonataDumpDoctrineMetaCommand.php index aa4d77c4..1aa967e9 100644 --- a/src/CoreBundle/Command/SonataDumpDoctrineMetaCommand.php +++ b/src/CoreBundle/Command/SonataDumpDoctrineMetaCommand.php @@ -144,7 +144,7 @@ private function filterMetadata(array $metadata, InputInterface $input, OutputIn if ($baseEntity) { $allowedMeta = array_filter( $metadata, - function ($meta) use ($baseEntity) { + static function ($meta) use ($baseEntity) { /* @var \Doctrine\ORM\Mapping\ClassMetadata $meta */ return $meta->rootEntityName === $baseEntity; } @@ -152,7 +152,7 @@ function ($meta) use ($baseEntity) { } elseif ($regex) { $allowedMeta = array_filter( $metadata, - function ($meta) use ($regex) { + static function ($meta) use ($regex) { /* @var \Doctrine\ORM\Mapping\ClassMetadata $meta */ return preg_match($regex, $meta->rootEntityName); } diff --git a/src/CoreBundle/Exporter/Exporter.php b/src/CoreBundle/Exporter/Exporter.php index ad6f6041..8501a586 100644 --- a/src/CoreBundle/Exporter/Exporter.php +++ b/src/CoreBundle/Exporter/Exporter.php @@ -68,7 +68,7 @@ public function getResponse($format, $filename, SourceIteratorInterface $source) throw new \RuntimeException('Invalid format'); } - $callback = function () use ($source, $writer) { + $callback = static function () use ($source, $writer) { $handler = Handler::create($source, $writer); $handler->export(); }; diff --git a/src/Form/Test/AbstractWidgetTestCase.php b/src/Form/Test/AbstractWidgetTestCase.php index f8d97702..5deebc1d 100644 --- a/src/Form/Test/AbstractWidgetTestCase.php +++ b/src/Form/Test/AbstractWidgetTestCase.php @@ -166,7 +166,7 @@ final protected function renderWidget(FormView $view, array $vars = []) */ final protected function cleanHtmlWhitespace($html) { - return preg_replace_callback('/\s*>([^<]+)([^<]+)'.trim($value[1]).'<'; }, $html); } @@ -178,7 +178,7 @@ final protected function cleanHtmlWhitespace($html) */ final protected function cleanHtmlAttributeWhitespace($html) { - return preg_replace_callback('~<([A-Z0-9]+) \K(.*?)>~i', function ($m) { + return preg_replace_callback('~<([A-Z0-9]+) \K(.*?)>~i', static function ($m) { return preg_replace('~\s*~', '', $m[0]); }, $html); } diff --git a/src/Form/Type/BasePickerType.php b/src/Form/Type/BasePickerType.php index a8fdae9d..4c218ebf 100644 --- a/src/Form/Type/BasePickerType.php +++ b/src/Form/Type/BasePickerType.php @@ -124,7 +124,7 @@ public function finishView(FormView $view, FormInterface $form, array $options) if (false !== strpos($key, 'dp_')) { // We remove 'dp_' and camelize the options names $dpKey = substr($key, 3); - $dpKey = preg_replace_callback('/_([a-z])/', function ($c) { + $dpKey = preg_replace_callback('/_([a-z])/', static function ($c) { return strtoupper($c[1]); }, $dpKey); diff --git a/src/Form/Type/BooleanType.php b/src/Form/Type/BooleanType.php index dbb2a321..18caa9be 100644 --- a/src/Form/Type/BooleanType.php +++ b/src/Form/Type/BooleanType.php @@ -68,7 +68,7 @@ public function configureOptions(OptionsResolver $resolver) 'label_type_no' => self::TYPE_NO, ], // Use directly translation_domain in SonataCoreBundle 4.0 - 'translation_domain' => function (Options $options) { + 'translation_domain' => static function (Options $options) { if ($options['catalogue']) { return $options['catalogue']; } diff --git a/src/Form/Type/ImmutableArrayType.php b/src/Form/Type/ImmutableArrayType.php index 06965b5c..2cc20f65 100644 --- a/src/Form/Type/ImmutableArrayType.php +++ b/src/Form/Type/ImmutableArrayType.php @@ -61,7 +61,7 @@ public function configureOptions(OptionsResolver $resolver) 'keys' => [], ]); - $resolver->setAllowedValues('keys', function ($value) { + $resolver->setAllowedValues('keys', static function ($value) { foreach ($value as $subValue) { if (!$subValue instanceof FormBuilderInterface && (!\is_array($subValue) || 3 !== \count($subValue))) { return false; diff --git a/src/Form/Validator/Constraints/InlineConstraint.php b/src/Form/Validator/Constraints/InlineConstraint.php index 0db51cf6..64d221bd 100755 --- a/src/Form/Validator/Constraints/InlineConstraint.php +++ b/src/Form/Validator/Constraints/InlineConstraint.php @@ -67,7 +67,7 @@ public function __wakeup() return; } - $this->method = function () { + $this->method = static function () { }; $this->serializingWarning = true; diff --git a/tests/CoreBundle/Form/EventListener/ResizeFormListenerTest.php b/tests/CoreBundle/Form/EventListener/ResizeFormListenerTest.php index cae212c3..1279e535 100644 --- a/tests/CoreBundle/Form/EventListener/ResizeFormListenerTest.php +++ b/tests/CoreBundle/Form/EventListener/ResizeFormListenerTest.php @@ -197,7 +197,7 @@ public function testPreSubmitDataWithClosure() $data = ['baz' => 'caz']; - $closure = function () use ($data) { + $closure = static function () use ($data) { return $data['baz']; }; diff --git a/tests/CoreBundle/Form/Type/BooleanTypeTest.php b/tests/CoreBundle/Form/Type/BooleanTypeTest.php index 7ef43c78..ba23d28b 100644 --- a/tests/CoreBundle/Form/Type/BooleanTypeTest.php +++ b/tests/CoreBundle/Form/Type/BooleanTypeTest.php @@ -52,7 +52,7 @@ public function testBuildForm() 'catalogue' => 'SonataCoreBundle', // Use directly translation_domain in SonataCoreBundle 4.0 - 'translation_domain' => function (Options $options) { + 'translation_domain' => static function (Options $options) { if ($options['catalogue']) { return $options['catalogue']; } diff --git a/tests/CoreBundle/Form/Type/EqualTypeTest.php b/tests/CoreBundle/Form/Type/EqualTypeTest.php index b4ae6308..10b67979 100644 --- a/tests/CoreBundle/Form/Type/EqualTypeTest.php +++ b/tests/CoreBundle/Form/Type/EqualTypeTest.php @@ -60,7 +60,7 @@ public function testGetDefaultOptions() $mock->expects($this->exactly(0)) ->method('trans') - ->will($this->returnCallback(function ($arg) { + ->will($this->returnCallback(static function ($arg) { return $arg; }) ); diff --git a/tests/CoreBundle/Form/Type/ImmutableArrayTypeTest.php b/tests/CoreBundle/Form/Type/ImmutableArrayTypeTest.php index 498cce69..0ac2d01c 100644 --- a/tests/CoreBundle/Form/Type/ImmutableArrayTypeTest.php +++ b/tests/CoreBundle/Form/Type/ImmutableArrayTypeTest.php @@ -82,19 +82,19 @@ public function testCallback() $builder = $this->createMock(TestFormBuilderInterface::class); $builder->expects($this->once())->method('add')->with( - $this->callback(function ($name) { + $this->callback(static function ($name) { return 'ttl' === $name; }), - $this->callback(function ($name) { + $this->callback(static function ($name) { return TextType::class === $name; }), - $this->callback(function ($name) { + $this->callback(static function ($name) { return $name === [1 => '1']; }) ); $self = $this; - $optionsCallback = function ($builder, $name, $type, $extra) use ($self) { + $optionsCallback = static function ($builder, $name, $type, $extra) use ($self) { $self->assertEquals(['foo', 'bar'], $extra); $self->assertEquals($name, 'ttl'); $self->assertEquals($type, TextType::class); diff --git a/tests/CoreBundle/Validator/Constraints/InlineConstraintTest.php b/tests/CoreBundle/Validator/Constraints/InlineConstraintTest.php index 525d472f..8c5838de 100755 --- a/tests/CoreBundle/Validator/Constraints/InlineConstraintTest.php +++ b/tests/CoreBundle/Validator/Constraints/InlineConstraintTest.php @@ -34,14 +34,14 @@ public function testIsClosure() $constraint = new InlineConstraint(['service' => 'foo', 'method' => 'bar']); $this->assertFalse($constraint->isClosure()); - $constraint = new InlineConstraint(['service' => 'foo', 'method' => function () { + $constraint = new InlineConstraint(['service' => 'foo', 'method' => static function () { }, 'serializingWarning' => true]); $this->assertTrue($constraint->isClosure()); } public function testGetClosure() { - $closure = function () { + $closure = static function () { return 'FOO'; }; @@ -75,7 +75,7 @@ public function testGetService() public function testClosureSerialization() { - $constraint = new InlineConstraint(['service' => 'foo', 'method' => function () { + $constraint = new InlineConstraint(['service' => 'foo', 'method' => static function () { }, 'serializingWarning' => true]); $expected = 'O:50:"Sonata\Form\Validator\Constraints\InlineConstraint":0:{}'; diff --git a/tests/CoreBundle/Validator/InlineValidatorTest.php b/tests/CoreBundle/Validator/InlineValidatorTest.php index 73de12bc..7f417585 100644 --- a/tests/CoreBundle/Validator/InlineValidatorTest.php +++ b/tests/CoreBundle/Validator/InlineValidatorTest.php @@ -72,7 +72,7 @@ public function testValidateWithConstraintIsClosure() $constraint->expects($this->once()) ->method('getClosure') - ->willReturn(function (ErrorElement $errorElement, $value) { + ->willReturn(static function (ErrorElement $errorElement, $value) { throw new ValidatorException($errorElement->getSubject().' is equal to '.$value); }); diff --git a/tests/Form/EventListener/ResizeFormListenerTest.php b/tests/Form/EventListener/ResizeFormListenerTest.php index eb58abd1..ba4a0834 100644 --- a/tests/Form/EventListener/ResizeFormListenerTest.php +++ b/tests/Form/EventListener/ResizeFormListenerTest.php @@ -177,7 +177,7 @@ public function testPreSubmitDataWithClosure() $data = ['baz' => 'caz']; - $closure = function () use ($data) { + $closure = static function () use ($data) { return $data['baz']; }; diff --git a/tests/Form/Type/BooleanTypeTest.php b/tests/Form/Type/BooleanTypeTest.php index ca90a01a..6978d1af 100644 --- a/tests/Form/Type/BooleanTypeTest.php +++ b/tests/Form/Type/BooleanTypeTest.php @@ -49,7 +49,7 @@ public function testBuildForm() 'catalogue' => 'SonataCoreBundle', // Use directly translation_domain in SonataCoreBundle 4.0 - 'translation_domain' => function (Options $options) { + 'translation_domain' => static function (Options $options) { if ($options['catalogue']) { return $options['catalogue']; } diff --git a/tests/Form/Type/EqualTypeTest.php b/tests/Form/Type/EqualTypeTest.php index 3c50bf2f..146750f9 100644 --- a/tests/Form/Type/EqualTypeTest.php +++ b/tests/Form/Type/EqualTypeTest.php @@ -57,7 +57,7 @@ public function testGetDefaultOptions() $mock->expects($this->exactly(0)) ->method('trans') - ->will($this->returnCallback(function ($arg) { + ->will($this->returnCallback(static function ($arg) { return $arg; }) ); diff --git a/tests/Form/Type/ImmutableArrayTypeTest.php b/tests/Form/Type/ImmutableArrayTypeTest.php index 2473aa67..7a2b34cc 100644 --- a/tests/Form/Type/ImmutableArrayTypeTest.php +++ b/tests/Form/Type/ImmutableArrayTypeTest.php @@ -79,19 +79,19 @@ public function testCallback() $builder = $this->createMock(TestFormBuilderInterface::class); $builder->expects($this->once())->method('add')->with( - $this->callback(function ($name) { + $this->callback(static function ($name) { return 'ttl' === $name; }), - $this->callback(function ($name) { + $this->callback(static function ($name) { return TextType::class === $name; }), - $this->callback(function ($name) { + $this->callback(static function ($name) { return $name === [1 => '1']; }) ); $self = $this; - $optionsCallback = function ($builder, $name, $type, $extra) use ($self) { + $optionsCallback = static function ($builder, $name, $type, $extra) use ($self) { $self->assertEquals(['foo', 'bar'], $extra); $self->assertEquals($name, 'ttl'); $self->assertEquals($type, TextType::class); diff --git a/tests/Form/Validator/Constraints/InlineConstraintTest.php b/tests/Form/Validator/Constraints/InlineConstraintTest.php index 7f8d3dcb..3e646c93 100755 --- a/tests/Form/Validator/Constraints/InlineConstraintTest.php +++ b/tests/Form/Validator/Constraints/InlineConstraintTest.php @@ -32,14 +32,14 @@ public function testIsClosure() $constraint = new InlineConstraint(['service' => 'foo', 'method' => 'bar']); $this->assertFalse($constraint->isClosure()); - $constraint = new InlineConstraint(['service' => 'foo', 'method' => function () { + $constraint = new InlineConstraint(['service' => 'foo', 'method' => static function () { }, 'serializingWarning' => true]); $this->assertTrue($constraint->isClosure()); } public function testGetClosure() { - $closure = function () { + $closure = static function () { return 'FOO'; }; @@ -73,7 +73,7 @@ public function testGetService() public function testClosureSerialization() { - $constraint = new InlineConstraint(['service' => 'foo', 'method' => function () { + $constraint = new InlineConstraint(['service' => 'foo', 'method' => static function () { }, 'serializingWarning' => true]); $expected = 'O:50:"Sonata\Form\Validator\Constraints\InlineConstraint":0:{}'; diff --git a/tests/Form/Validator/InlineValidatorTest.php b/tests/Form/Validator/InlineValidatorTest.php index 80bce98f..c4caf498 100644 --- a/tests/Form/Validator/InlineValidatorTest.php +++ b/tests/Form/Validator/InlineValidatorTest.php @@ -70,7 +70,7 @@ public function testValidateWithConstraintIsClosure() $constraint->expects($this->once()) ->method('getClosure') - ->willReturn(function (ErrorElement $errorElement, $value) { + ->willReturn(static function (ErrorElement $errorElement, $value) { throw new ValidatorException($errorElement->getSubject().' is equal to '.$value); });