1 | <?php |
||
31 | abstract class AbstractShape |
||
32 | { |
||
33 | const TYPE_EXCEPTION_MESSAGE = 'The %s class expects a value of type %s. Received a value of type %s instead.'; |
||
34 | |||
35 | /** @var mixed */ |
||
36 | protected $value; |
||
37 | |||
38 | /** |
||
39 | * A map of Strong Types => native types. |
||
40 | * |
||
41 | * @var array<string> |
||
42 | */ |
||
43 | protected $typemap = [ |
||
44 | 'Skyzyx\\StrongTypes\\BooleanType' => 'boolean', |
||
45 | 'Skyzyx\\StrongTypes\\Collection' => 'array', |
||
46 | 'Skyzyx\\StrongTypes\\IntegerType' => 'integer', |
||
47 | 'Skyzyx\\StrongTypes\\FloatType' => 'double', |
||
48 | 'Skyzyx\\StrongTypes\\StringType' => 'string', |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * Constructs a new instance of this object. |
||
53 | * |
||
54 | * @param mixed $value The value to assign to the instance. |
||
55 | */ |
||
56 | public function __construct($value = null) |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | public function getValue() |
||
69 | |||
70 | /** |
||
71 | * Returns the typemap. |
||
72 | * |
||
73 | * @return array<string> The typemap. |
||
74 | */ |
||
75 | public function getTypeMap() |
||
79 | |||
80 | /** |
||
81 | * Gets the name of the native type that pairs with the Strong Type. |
||
82 | * |
||
83 | * @param ShapeInterface $value A strongly-typed object. |
||
84 | * @return string The name of the native type. |
||
|
|||
85 | */ |
||
86 | public function getNativeType(ShapeInterface $value) |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | public function __toString() |
||
104 | } |
||
105 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.