Completed
Push — develop ( 722f70...af048b )
by Jaap
15:12 queued 05:04
created

Parser/Documentation/Api/FromReflectionFactory.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2016 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Application\Parser\Documentation\Api;
14
15
use InvalidArgumentException;
16
use League\Event\Emitter;
17
use phpDocumentor\DomainModel\Parser\ApiParsingCompleted;
18
use phpDocumentor\DomainModel\Parser\ApiParsingStarted;
19
use phpDocumentor\DomainModel\Parser\Documentation\Api\Api;
20
use phpDocumentor\DomainModel\Parser\Documentation\Api\Definition;
21
use phpDocumentor\DomainModel\Parser\Documentation\DocumentGroup;
22
use phpDocumentor\DomainModel\Parser\Documentation\DocumentGroup\Definition as DocumentGroupDefinitionInterface;
23
use phpDocumentor\DomainModel\Parser\Documentation\DocumentGroupFactory;
24
use phpDocumentor\Reflection\ProjectFactory;
25
use phpDocumentor\Reflection\Php\Factory\File;
26
27
final class FromReflectionFactory implements DocumentGroupFactory
28
{
29
    /** @var Emitter */
30
    private $emitter;
31
32
    /**
33
     * @var ProjectFactory
34
     */
35
    private $projectFactory;
36
37
    /**
38
     * @param Emitter $emitter
39
     * @param ProjectFactory $projectFactory
40
     */
41
    public function __construct(Emitter $emitter, ProjectFactory $projectFactory)
42
    {
43
        $this->emitter = $emitter;
44
        $this->projectFactory = $projectFactory;
45
    }
46
47
    /**
48
     * Creates Document group using the provided definition.
49
     *
50
     * @param DocumentGroupDefinitionInterface $definition
51
     * @return DocumentGroup
52
     */
53
    public function create(DocumentGroupDefinitionInterface $definition)
54
    {
55
        /** @var Definition $definition */
56
        if (!$this->matches($definition)) {
57
            throw new InvalidArgumentException('Definition must be an instance of ' . Definition::class);
58
        }
59
60
        // TODO: Read title (My Project) from configuration
61
        $this->emitter->emit(new ApiParsingStarted($definition));
62
        $project = $this->projectFactory->create('My Project', $definition->getFiles());
63
        $this->emitter->emit(new ApiParsingCompleted($definition));
64
65
        return new Api($definition->getFormat(), $project);
0 ignored issues
show
$project of type object<phpDocumentor\Reflection\Project> is not a sub-type of object<phpDocumentor\Reflection\Php\Project>. It seems like you assume a concrete implementation of the interface phpDocumentor\Reflection\Project to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
66
    }
67
68
    /**
69
     * Will return true when this factory can handle the provided definition.
70
     *
71
     * @param DocumentGroupDefinitionInterface $definition
72
     * @return boolean
73
     */
74
    public function matches(DocumentGroupDefinitionInterface $definition)
75
    {
76
        if ($definition instanceof Definition) {
77
            return true;
78
        }
79
80
        return false;
81
    }
82
}
83