Skip to content

Commit 4056a40

Browse files
committed
Replace unused Entity private method
1 parent 4d0110f commit 4056a40

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

rector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878

7979
// private method called via getPrivateMethodInvoker
8080
RemoveUnusedPrivateMethodRector::class => [
81-
__DIR__ . '/system/Entity/Entity.php',
8281
__DIR__ . '/tests/system/Test/ReflectionHelperTest.php',
8382
],
8483

system/Entity/Entity.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,20 +389,6 @@ protected function castAs($value, string $attribute, string $method = 'get')
389389
return $handlers[$type]::$method($value, $params);
390390
}
391391

392-
/**
393-
* Cast as JSON
394-
*
395-
* @param mixed $value
396-
*
397-
* @throws CastException
398-
*
399-
* @return mixed
400-
*/
401-
private function castAsJson($value, bool $asArray = false)
402-
{
403-
return JsonCast::get($value, $asArray ? ['array'] : []);
404-
}
405-
406392
/**
407393
* Support for json_encode()
408394
*

tests/system/Entity/EntityTest.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\Entity;
1313

14+
use Closure;
1415
use CodeIgniter\Entity\Exceptions\CastException;
1516
use CodeIgniter\HTTP\URI;
1617
use CodeIgniter\I18n\Time;
@@ -589,34 +590,43 @@ public function testCastAsJSONErrorUTF8()
589590

590591
public function testCastAsJSONSyntaxError()
591592
{
592-
$entity = new Entity();
593+
$method = Closure::bind(static function (string $value) {
594+
$entity = new Entity();
595+
$entity->casts['dummy'] = 'json[array]';
593596

594-
$method = $this->getPrivateMethodInvoker($entity, 'castAsJson');
597+
return $entity->castAs($value, 'dummy');
598+
}, null, Entity::class);
595599

596600
$this->expectException(CastException::class);
597601
$this->expectExceptionMessage('Syntax error, malformed JSON');
598602

599-
$method('{ this is bad string', true);
603+
$method('{ this is bad string');
600604
}
601605

602606
public function testCastAsJSONAnotherErrorDepth()
603607
{
604-
$entity = new Entity();
608+
$method = Closure::bind(static function (string $value) {
609+
$entity = new Entity();
610+
$entity->casts['dummy'] = 'json[array]';
605611

606-
$method = $this->getPrivateMethodInvoker($entity, 'castAsJson');
612+
return $entity->castAs($value, 'dummy');
613+
}, null, Entity::class);
607614

608615
$this->expectException(CastException::class);
609616
$this->expectExceptionMessage('Maximum stack depth exceeded');
610617

611618
$string = '{' . str_repeat('"test":{', 513) . '"test":"value"' . str_repeat('}', 513) . '}';
612-
613-
$method($string, true);
619+
$method($string);
614620
}
615621

616622
public function testCastAsJSONControlCharCheck()
617623
{
618-
$entity = new Entity();
619-
$method = $this->getPrivateMethodInvoker($entity, 'castAsJson');
624+
$method = Closure::bind(static function (string $value) {
625+
$entity = new Entity();
626+
$entity->casts['dummy'] = 'json[array]';
627+
628+
return $entity->castAs($value, 'dummy');
629+
}, null, Entity::class);
620630

621631
$this->expectException(CastException::class);
622632
$this->expectExceptionMessage('Unexpected control character found');
@@ -628,8 +638,12 @@ public function testCastAsJSONControlCharCheck()
628638

629639
public function testCastAsJSONStateMismatch()
630640
{
631-
$entity = new Entity();
632-
$method = $this->getPrivateMethodInvoker($entity, 'castAsJson');
641+
$method = Closure::bind(static function (string $value) {
642+
$entity = new Entity();
643+
$entity->casts['dummy'] = 'json[array]';
644+
645+
return $entity->castAs($value, 'dummy');
646+
}, null, Entity::class);
633647

634648
$this->expectException(CastException::class);
635649
$this->expectExceptionMessage('Underflow or the modes mismatch');

0 commit comments

Comments
 (0)