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\AuthorDescriptor; |
||
20 | use phpDocumentor\Reflection\DocBlock\Tags\Author; |
||
21 | |||
22 | /** |
||
23 | * Constructs a new descriptor from the Reflector for an `@author` tag. |
||
24 | * |
||
25 | * This object will read the reflected information for the `@author` tag and create a {@see AuthorDescriptor} object |
||
26 | * that can be used in the rest of the application and templates. |
||
27 | */ |
||
28 | class AuthorAssembler extends AssemblerAbstract |
||
29 | { |
||
30 | /** |
||
31 | * Creates a new Descriptor from the given Reflector. |
||
32 | * |
||
33 | * @param Author $data |
||
34 | * |
||
35 | * @return AuthorDescriptor |
||
36 | */ |
||
37 | public function create($data) |
||
38 | { |
||
39 | $descriptor = new AuthorDescriptor($data->getName()); |
||
40 | $descriptor->setDescription($data->getDescription()); |
||
0 ignored issues
–
show
|
|||
41 | |||
42 | return $descriptor; |
||
0 ignored issues
–
show
The return type of
return $descriptor; (phpDocumentor\Descriptor\Tag\AuthorDescriptor ) is incompatible with the return type declared by the interface phpDocumentor\Descriptor...emblerInterface::create of type phpDocumentor\Descriptor...r\Descriptor\Collection .
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: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function
Loading history...
|
|||
43 | } |
||
44 | } |
||
45 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.