diff --git a/LICENSE b/LICENSE index 460b317..d1524fe 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2016 Matthias Noback +Copyright (c) Matthias Noback Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index a599cb3..a15163d 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ class OrderSeats And use it like this: ```php -$form = $this->factory->create(new OrderSeatsFormType()); +$form = $this->factory->create(OrderSeatsFormType::class); $form->submit($request); $command = $form->getData(); $command->id = Uuid::uuid4(); @@ -74,7 +74,7 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio [ico-version]: https://img.shields.io/packagist/v/matthiasnoback/convenient-immutability.svg?style=flat-square [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square [ico-coveralls]: https://img.shields.io/coveralls/matthiasnoback/convenient-immutability.svg?style=flat-square -[ico-travis]: https://img.shields.io/travis/matthiasnoback/convenient-immutability.svg?style=flat-square +[ico-travis]: https://img.shields.io/travis/matthiasnoback/convenient-immutability.svg?style=flat-square [ico-downloads]: https://img.shields.io/packagist/dt/matthiasnoback/convenient-immutability.svg?style=flat-square [link-packagist]: https://packagist.org/packages/matthiasnoback/convenient-immutability @@ -82,4 +82,4 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio [link-travis]: https://travis-ci.org/matthiasnoback/convenient-immutability [link-downloads]: https://packagist.org/packages/matthiasnoback/convenient-immutability [link-author]: https://github.com/matthiasnoback -[link-contributors]: ../../contributors \ No newline at end of file +[link-contributors]: ../../contributors diff --git a/src/Immutable.php b/src/Immutable.php index 2ae6562..28dc1b1 100644 --- a/src/Immutable.php +++ b/src/Immutable.php @@ -2,6 +2,10 @@ namespace ConvenientImmutability; +use LogicException; +use ReflectionObject; +use const PHP_VERSION_ID; + trait Immutable { private $_defaultValues = []; @@ -17,7 +21,7 @@ trait Immutable public function __construct() { // take over all user-defined non-static properties - foreach ((new \ReflectionObject($this))->getProperties() as $property) { + foreach ((new ReflectionObject($this))->getProperties() as $property) { $propertyName = $property->getName(); if (isset(self::$_doNotTakeOverProperties[$propertyName]) || $property->isStatic()) { @@ -25,7 +29,7 @@ public function __construct() } $this->_userDefinedProperties[$propertyName] = true; - if (\PHP_VERSION_ID < 70400 || $property->isInitialized($this)) { + if (PHP_VERSION_ID < 70400 || $property->isInitialized($this)) { $this->_defaultValues[$propertyName] = $property->getValue($this); } unset($this->{$propertyName}); @@ -35,11 +39,11 @@ public function __construct() final public function __set($name, $value) { if (!isset($this->_userDefinedProperties[$name])) { - throw new \LogicException('Unknown property "' . $name . '"'); + throw new LogicException('Unknown property "' . $name . '"'); } if (array_key_exists($name, $this->_userDefinedValues)) { - throw new \LogicException('You can not overwrite the value for property "' . $name . '"'); + throw new LogicException('You can not overwrite the value for property "' . $name . '"'); } $this->_userDefinedValues[$name] = $value; @@ -48,7 +52,7 @@ final public function __set($name, $value) final public function __get($name) { if (!isset($this->_userDefinedProperties[$name])) { - throw new \LogicException('Unknown property "' . $name . '"'); + throw new LogicException('Unknown property "' . $name . '"'); } if (array_key_exists($name, $this->_userDefinedValues)) { diff --git a/test/FormIntegrationTest.php b/test/FormIntegrationTest.php index a991e8a..100ede3 100644 --- a/test/FormIntegrationTest.php +++ b/test/FormIntegrationTest.php @@ -7,12 +7,12 @@ use Ramsey\Uuid\Uuid; use Symfony\Component\Form\Test\TypeTestCase; -class FormIntegrationTest extends TypeTestCase +final class FormIntegrationTest extends TypeTestCase { /** * @test */ - public function it_works_with_a_standard_use_case_for_command_objects() + public function it_works_with_a_standard_use_case_for_command_objects(): void { $id = Uuid::uuid4(); $form = $this->factory->create(OrderSeatsFormType::class); diff --git a/test/ImmutableTraitTest.php b/test/ImmutableTraitTest.php index f791730..ef291ab 100644 --- a/test/ImmutableTraitTest.php +++ b/test/ImmutableTraitTest.php @@ -8,12 +8,12 @@ use LogicException; use PHPUnit\Framework\TestCase; -class ImmutableTraitTest extends TestCase +final class ImmutableTraitTest extends TestCase { /** * @return array */ - public function objectProvider() + public function objectProvider(): array { $foo = new Foo(); @@ -32,7 +32,7 @@ public function objectProvider() * @test * @dataProvider objectProvider */ - public function it_allows_one_assignment_per_property(Foo $foo) + public function it_allows_one_assignment_per_property(Foo $foo): void { $foo->bar = 1; $foo->baz = 2; @@ -45,7 +45,7 @@ public function it_allows_one_assignment_per_property(Foo $foo) * @test * @dataProvider objectProvider */ - public function it_fails_when_a_property_gets_reassigned(Foo $foo) + public function it_fails_when_a_property_gets_reassigned(Foo $foo): void { $foo->bar = 1; @@ -59,7 +59,7 @@ public function it_fails_when_a_property_gets_reassigned(Foo $foo) * @test * @dataProvider objectProvider */ - public function it_fails_to_assign_values_to_undefined_properties(Foo $foo) + public function it_fails_to_assign_values_to_undefined_properties(Foo $foo): void { $this->expectException(LogicException::class); $foo->bang = 1; @@ -69,7 +69,7 @@ public function it_fails_to_assign_values_to_undefined_properties(Foo $foo) * @test * @dataProvider objectProvider */ - public function it_fails_to_retrieve_values_from_undefined_properties(Foo $foo) + public function it_fails_to_retrieve_values_from_undefined_properties(Foo $foo): void { $this->expectException(LogicException::class); $foo->bang; @@ -79,7 +79,7 @@ public function it_fails_to_retrieve_values_from_undefined_properties(Foo $foo) * @test * @dataProvider objectProvider */ - public function it_returns_null_for_properties_that_have_no_assigned_value(Foo $foo) + public function it_returns_null_for_properties_that_have_no_assigned_value(Foo $foo): void { $this->assertSame(null, $foo->bar); } @@ -88,7 +88,7 @@ public function it_returns_null_for_properties_that_have_no_assigned_value(Foo $ * @test * @dataProvider objectProvider */ - public function it_returns_the_default_attribute_value_of_properties_that_have_no_assigned_value(Foo $foo) + public function it_returns_the_default_attribute_value_of_properties_that_have_no_assigned_value(Foo $foo): void { $this->assertSame([], $foo->bazzes); } @@ -97,7 +97,7 @@ public function it_returns_the_default_attribute_value_of_properties_that_have_n * @test * @dataProvider objectProvider */ - public function it_should_have_the_same_values_after_deserialization(Foo $foo) + public function it_should_have_the_same_values_after_deserialization(Foo $foo): void { $foo->bar = 'bar'; $foo->baz = 1; diff --git a/test/Resources/OrderSeats.php b/test/Resources/OrderSeats.php index ef08b7c..960fcd6 100644 --- a/test/Resources/OrderSeats.php +++ b/test/Resources/OrderSeats.php @@ -4,7 +4,7 @@ use ConvenientImmutability\Immutable; -class OrderSeats +final class OrderSeats { use Immutable; diff --git a/test/Resources/OrderSeatsFormType.php b/test/Resources/OrderSeatsFormType.php index 994e03c..6926878 100644 --- a/test/Resources/OrderSeatsFormType.php +++ b/test/Resources/OrderSeatsFormType.php @@ -7,7 +7,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -class OrderSeatsFormType extends AbstractType +final class OrderSeatsFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) {