Skip to content

Commit

Permalink
[TASK] Speed up type determination a little bit
Browse files Browse the repository at this point in the history
Related: #38
  • Loading branch information
brotkrueml committed Mar 21, 2020
1 parent 035c9d8 commit 2a8a863
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
4 changes: 1 addition & 3 deletions Classes/Core/Model/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ public function isEmpty(): bool

private function getType(): string
{
$classNameParts = \explode('\\', static::class);

return \end($classNameParts);
return \substr(\strrchr(static::class, '\\') ?: '', 1);
}

/**
Expand Down
18 changes: 6 additions & 12 deletions Tests/Unit/Core/Model/AbstractTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,9 @@ public function toArrayIsCorrectWhenAddPropertyCalledMultipleTimesOnTheSamePrope
$this->subject->addProperty('isAccessibleForFree', false);
$this->subject->addProperty('isAccessibleForFree', true);

$this->subject->addProperty('image', new class extends AbstractType {
protected $properties = ['someName' => 'someValue 1'];
});
$this->subject->addProperty('image', new class extends AbstractType {
protected $properties = ['someName' => 'someValue 2'];
});
$this->subject->addProperty('image', new class extends AbstractType {
protected $properties = ['someName' => 'someValue 3'];
});
$this->subject->addProperty('image', (new FixtureImage())->setProperty('name', 'someValue 1'));
$this->subject->addProperty('image', (new FixtureImage())->setProperty('name', 'someValue 2'));
$this->subject->addProperty('image', (new FixtureImage())->setProperty('name', 'someValue 3'));

$actual = $this->subject->toArray();

Expand All @@ -267,9 +261,9 @@ public function toArrayIsCorrectWhenAddPropertyCalledMultipleTimesOnTheSamePrope
$actual['isAccessibleForFree']
);
self::assertSame(['name 1', 'name 2', 'name 3'], $actual['name']);
self::assertSame('someValue 1', $actual['image'][0]['someName']);
self::assertSame('someValue 2', $actual['image'][1]['someName']);
self::assertSame('someValue 3', $actual['image'][2]['someName']);
self::assertSame('someValue 1', $actual['image'][0]['name']);
self::assertSame('someValue 2', $actual['image'][1]['name']);
self::assertSame('someValue 3', $actual['image'][2]['name']);
}

/**
Expand Down

0 comments on commit 2a8a863

Please sign in to comment.