diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b54219..223bdad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### 1.2.0 * requires at least PHP 8.1, CakePHP 5.0 and PHPUnit 10; * provides its own `phpUri` library; -* `ScanEntity` no longer extends any `Entity` class (which has been removed). For now it implements `ArrayAccess`; +* `ScanEntity` no longer extends any `Entity` class (which has been removed) and directly implements `ArrayAccess`; * added and fixed typehints, removed deprecations; * added tests for PHP 8.3. diff --git a/src/ScanEntity.php b/src/ScanEntity.php index aae2dd6..b6bc7b9 100644 --- a/src/ScanEntity.php +++ b/src/ScanEntity.php @@ -66,8 +66,8 @@ public function __call(string $name, mixed $arguments): mixed { if (method_exists(Response::class, $name)) { $Response = (new Response()) - ->withHeader('location', $this->get('location')) - ->withStatus($this->get('code')); + ->withHeader('location', $this['location']) + ->withStatus($this['code']); /** @var callable $name */ $name = [$Response, $name]; } @@ -79,29 +79,6 @@ public function __call(string $name, mixed $arguments): mixed return call_user_func_array($name, $arguments); } - /** - * Get method. - * - * Alias for `offsetGet()` - * @param string $name Property name - * @return mixed - */ - public function get(string $name): mixed { - return $this->offsetGet($name); - } - - /** - * Set method. - * - * Alias for `offsetSet()` - * @param string $name Property name - * @param mixed $value Property value - * @return void - */ - public function set(string $name, mixed $value): void { - $this->offsetSet($name, $value); - } - /** * @inheritDoc */ diff --git a/src/Utility/LinkScanner.php b/src/Utility/LinkScanner.php index 5b4cb58..60a0b30 100644 --- a/src/Utility/LinkScanner.php +++ b/src/Utility/LinkScanner.php @@ -367,7 +367,7 @@ public function export(?string $filename = null): string } if ($this->getConfig('exportOnlyBadResults')) { - $this->ResultScan = new ResultScan($this->ResultScan->filter(fn(ScanEntity $item): bool => $item->get('code') >= 400)); + $this->ResultScan = new ResultScan($this->ResultScan->filter(fn(ScanEntity $item): bool => $item['code'] >= 400)); } $filename = $this->_getAbsolutePath($filename ?: sprintf('results_%s_%s', $this->hostname, $this->startTime)); diff --git a/tests/TestCase/ScanEntityTest.php b/tests/TestCase/ScanEntityTest.php index d1d839c..6396563 100644 --- a/tests/TestCase/ScanEntityTest.php +++ b/tests/TestCase/ScanEntityTest.php @@ -35,7 +35,7 @@ public function setUp(): void { parent::setUp(); - $this->ScanEntity = new ScanEntity([ + $this->ScanEntity ??= new ScanEntity([ 'code' => 200, 'external' => false, 'location' => 'https://example.com/location', @@ -50,24 +50,21 @@ public function setUp(): void */ public function testCall(): void { - $statusCodes = [ - 200 => true, - 301 => false, - 404 => false, - ]; - - foreach ($statusCodes as $code => $expectedValue) { - $this->ScanEntity->set('code', $code); + foreach ([ + 200 => true, + 301 => false, + 404 => false, + ] as $code => $expectedValue) { + $this->ScanEntity['code'] = $code; $this->assertEquals($expectedValue, $this->ScanEntity->isSuccess()); } - $statusCodes = [ - 200 => false, - 301 => true, - 404 => false, - ]; - foreach ($statusCodes as $code => $expectedValue) { - $this->ScanEntity->set('code', $code); + foreach ([ + 200 => false, + 301 => true, + 404 => false, + ] as $code => $expectedValue) { + $this->ScanEntity['code'] = $code; $this->assertEquals($expectedValue, $this->ScanEntity->isRedirect()); } @@ -96,20 +93,10 @@ public function testConstruct(): void */ public function testOffsetMethods(): void { - $this->ScanEntity['name'] = 'value'; - $this->assertSame('value', $this->ScanEntity['name']); - $this->assertTrue(isset($this->ScanEntity['name'])); - unset($this->ScanEntity['name']); - $this->assertFalse(isset($this->ScanEntity['name'])); - } - - /** - * @test - * @uses \LinkScanner\ScanEntity::get() - * @uses \LinkScanner\ScanEntity::set() - */ - public function testGetAndSetMethods(): void - { - $this->markTestIncomplete(); + $this->ScanEntity->key = 'value'; + $this->assertSame('value', $this->ScanEntity->key); + $this->assertTrue(isset($this->ScanEntity->key)); + unset($this->ScanEntity->key); + $this->assertFalse(isset($this->ScanEntity->key)); } } diff --git a/tests/TestCase/Utility/LinkScannerTest.php b/tests/TestCase/Utility/LinkScannerTest.php index 22f2697..3631be1 100644 --- a/tests/TestCase/Utility/LinkScannerTest.php +++ b/tests/TestCase/Utility/LinkScannerTest.php @@ -290,9 +290,9 @@ public function testScan(): void $hostname = get_hostname_from_url($this->fullBaseUrl); foreach ($LinkScanner->ResultScan as $item) { - $this->assertMatchesRegularExpression(sprintf('/^https?:\/\/%s/', preg_quote($hostname)), $item->get('url')); - $this->assertContains($item->get('code'), [200, 500]); - $this->assertStringStartsWith('text/html', $item->get('type')); + $this->assertMatchesRegularExpression(sprintf('/^https?:\/\/%s/', preg_quote($hostname)), $item['url']); + $this->assertContains($item['code'], [200, 500]); + $this->assertStringStartsWith('text/html', $item['type']); } /** @var \LinkScanner\Utility\LinkScanner&\PHPUnit\Framework\MockObject\MockObject $LinkScanner */ @@ -408,11 +408,11 @@ public function testScanFromTests(): void $LinkScanner->setConfig('maxDepth', 1)->scan(); $this->assertCount(1, $LinkScanner->ResultScan); $item = $LinkScanner->ResultScan->first(); - $this->assertSame($item->get('code'), 200); - $this->assertFalse($item->get('external')); - $this->assertEmpty($item->get('referer')); - $this->assertStringStartsWith('text/html', $item->get('type')); - $this->assertSame($item->get('url'), 'http://localhost'); + $this->assertSame($item['code'], 200); + $this->assertFalse($item['external']); + $this->assertEmpty($item['referer']); + $this->assertStringStartsWith('text/html', $item['type']); + $this->assertSame($item['url'], 'http://localhost'); $LinkScanner = $this->getLinkScannerClientReturnsFromTests(); $LinkScanner->setConfig('exportOnlyBadResults', true)->scan();