1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of the KleijnWeb\PhpApi\Hydrator package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace KleijnWeb\PhpApi\Hydrator\Processors\Factory; |
10
|
|
|
|
11
|
|
|
use KleijnWeb\PhpApi\Descriptions\Description\Schema\ScalarSchema; |
12
|
|
|
use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema; |
13
|
|
|
use KleijnWeb\PhpApi\Hydrator\ProcessorBuilder; |
14
|
|
|
use KleijnWeb\PhpApi\Hydrator\Processors\Processor; |
15
|
|
|
use KleijnWeb\PhpApi\Hydrator\Processors\Scalar\BoolProcessor; |
16
|
|
|
use KleijnWeb\PhpApi\Hydrator\Processors\Scalar\IntegerProcessor; |
17
|
|
|
use KleijnWeb\PhpApi\Hydrator\Processors\Scalar\NullProcessor; |
18
|
|
|
use KleijnWeb\PhpApi\Hydrator\Processors\Scalar\NumberProcessor; |
19
|
|
|
use KleijnWeb\PhpApi\Hydrator\Processors\Scalar\StringProcessor; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author John Kleijn <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class ScalarFactory implements Factory |
25
|
|
|
{ |
26
|
|
|
const PRIORITY = 900; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected static $primitiveMap = [ |
32
|
|
|
Schema::TYPE_STRING => StringProcessor::class, |
33
|
|
|
Schema::TYPE_INT => IntegerProcessor::class, |
34
|
|
|
Schema::TYPE_BOOL => BoolProcessor::class, |
35
|
|
|
Schema::TYPE_NUMBER => NumberProcessor::class, |
36
|
|
|
Schema::TYPE_NULL => NullProcessor::class, |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param Schema $schema |
41
|
|
|
* @param ProcessorBuilder $builder |
42
|
|
|
* @return Processor|null |
43
|
|
|
*/ |
44
|
|
|
public function create(Schema $schema, ProcessorBuilder $builder) |
45
|
|
|
{ |
46
|
|
|
if (!$schema instanceof ScalarSchema) { |
47
|
|
|
return null; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (!isset(self::$primitiveMap[$schema->getType()])) { |
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
$className = self::$primitiveMap[$schema->getType()]; |
54
|
|
|
|
55
|
|
|
return $hydrator = new $className($schema); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return int |
60
|
|
|
*/ |
61
|
|
|
public function getPriority(): int |
62
|
|
|
{ |
63
|
|
|
return self::PRIORITY; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.