Skip to content

Commit

Permalink
Merge pull request #108 from samsonasik/php74-syntax
Browse files Browse the repository at this point in the history
[Php74] Apply PHP 7.4 syntax and typed properties (for private modifiers)
  • Loading branch information
Ocramius authored Sep 26, 2021
2 parents b9e5b98 + 4a5b03d commit e9e2dcc
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 38 deletions.
5 changes: 0 additions & 5 deletions src/Generator/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,6 @@ public function removeExtentedClass()
*/
public function setImplementedInterfaces(array $implementedInterfaces)
{
array_map(function ($implementedInterface) {
// This loop is just validating that the given `$implementedInterfaces` contains valid syntax/symbols
return TypeGenerator::fromTypeString($implementedInterface);
}, $implementedInterfaces);

$this->implementedInterfaces = $implementedInterfaces;
return $this;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Generator/DocBlock/Tag/VarTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

class VarTag extends AbstractTypeableTag implements TagInterface
{
/** @var string|null */
private $variableName;
private ?string $variableName = null;

/**
* @param string|string[] $types
Expand Down
7 changes: 4 additions & 3 deletions src/Generator/FileGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ public static function fromArray(array $values)
$fileGenerator->setRequiredFiles($value);
break;
case 'declares':
$fileGenerator->setDeclares(array_map(static function ($directive, $value) {
return DeclareStatement::fromArray([$directive => $value]);
}, array_keys($value), $value));
$fileGenerator->setDeclares(
array_map(static fn($directive, $value) =>
DeclareStatement::fromArray([$directive => $value]), array_keys($value), $value)
);
break;
default:
if (property_exists($fileGenerator, $name)) {
Expand Down
8 changes: 5 additions & 3 deletions src/Generator/MethodGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,11 @@ public function setReturnsReference($returnsReference)
*/
private function sortParameters(): void
{
uasort($this->parameters, static function (ParameterGenerator $item1, ParameterGenerator $item2) {
return $item1->getPosition() <=> $item2->getPosition();
});
uasort(
$this->parameters,
static fn(ParameterGenerator $item1, ParameterGenerator $item2)
=> $item1->getPosition() <=> $item2->getPosition()
);
}

/**
Expand Down
6 changes: 2 additions & 4 deletions test/Generator/DocBlock/Tag/VarTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
*/
class VarTagTest extends TestCase
{
/** @var VarTag */
private $tag;
private VarTag $tag;

/** @var TagManager */
private $tagManager;
private TagManager $tagManager;

protected function setUp(): void
{
Expand Down
10 changes: 3 additions & 7 deletions test/Generator/MethodGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ public function testSetMethodParameters()

$params = $methodGenerator->getParameters();

$sorting = array_map(static function (ParameterGenerator $parameter): string {
return $parameter->getName();
}, $params);
$sorting = array_map(static fn(ParameterGenerator $parameter): string => $parameter->getName(), $params);

self::assertEquals(['foo' => 'foo', 'baz' => 'baz', 'bar' => 'bar'], $sorting);
}
Expand Down Expand Up @@ -427,10 +425,8 @@ public function returnTypeHintClasses()

return array_values(array_filter(
$parameters,
function (array $parameter) {
return PHP_VERSION_ID >= 80000
|| $parameter[0] !== Php80Types::class;
}
static fn(array $parameter) => PHP_VERSION_ID >= 80000
|| $parameter[0] !== Php80Types::class
));
}

Expand Down
14 changes: 5 additions & 9 deletions test/Generator/ParameterGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,20 +480,16 @@ public function reflectionHints()

$compatibleParameters = array_filter(
$parameters,
function (array $parameter) {
return PHP_VERSION_ID >= 70200
|| (
false === strpos($parameter[3], 'object')
);
}
static fn(array $parameter) => PHP_VERSION_ID >= 70200
|| (
false === strpos($parameter[3], 'object')
)
);

// just re-organizing the keys so that the phpunit data set makes sense in errors:
return array_combine(
array_map(
function (array $definition) {
return $definition[0] . '#' . $definition[1];
},
static fn(array $definition) => $definition[0] . '#' . $definition[1],
$compatibleParameters
),
$compatibleParameters
Expand Down
4 changes: 2 additions & 2 deletions test/Generator/TestAsset/TestClassWithManyProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class TestClassWithManyProperties

protected $_barProperty = 1.1115;

private static $_bazStaticProperty = self::FOO;
private static string $_bazStaticProperty = self::FOO;

private $_bazProperty = [true, false, true];
private array $_bazProperty = [true, false, true];

protected $_complexType = [
5,
Expand Down
4 changes: 1 addition & 3 deletions test/Generator/TypeGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ public function validClassName()
{
return array_filter(
$this->validType(),
function (array $pair) {
return 0 === strpos($pair[1], '\\');
}
static fn(array $pair) => 0 === strpos($pair[1], '\\')
);
}

Expand Down

0 comments on commit e9e2dcc

Please sign in to comment.