These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | /** |
||
5 | * This file is part of phpDocumentor. |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | * |
||
10 | * @author Mike van Riel <[email protected]> |
||
11 | * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
||
12 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
13 | * @link http://phpdoc.org |
||
14 | */ |
||
15 | |||
16 | namespace phpDocumentor\Descriptor\Builder\Reflector\Tags; |
||
17 | |||
18 | use phpDocumentor\Descriptor\Builder\Reflector\AssemblerAbstract; |
||
19 | use phpDocumentor\Descriptor\Tag\ParamDescriptor; |
||
20 | use phpDocumentor\Reflection\DocBlock\Tags\Param; |
||
21 | |||
22 | /** |
||
23 | * Constructs a new descriptor from the Reflector for an `@param` tag. |
||
24 | * |
||
25 | * This object will read the reflected information for the `@param` tag and create a {@see ParamDescriptor} object that |
||
26 | * can be used in the rest of the application and templates. |
||
27 | */ |
||
28 | class ParamAssembler extends AssemblerAbstract |
||
29 | { |
||
30 | /** |
||
31 | * Creates a new Descriptor from the given Reflector. |
||
32 | * |
||
33 | * @param Param $data |
||
34 | * |
||
35 | * @return ParamDescriptor |
||
36 | */ |
||
37 | 1 | public function create($data) |
|
38 | { |
||
39 | 1 | $descriptor = new ParamDescriptor($data->getName()); |
|
40 | 1 | $descriptor->setDescription($data->getDescription()); |
|
41 | 1 | $descriptor->setVariableName($data->getVariableName()); |
|
42 | 1 | $descriptor->setType(AssemblerAbstract::deduplicateTypes($data->getType())); |
|
43 | |||
44 | 1 | return $descriptor; |
|
0 ignored issues
–
show
|
|||
45 | } |
||
46 | } |
||
47 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.