Completed
Push — develop ( 80740b...61b5c3 )
by Mike
10:20
created

src/phpDocumentor/Plugin/Core/ServiceProvider.php (2 issues)

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
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\Plugin\Core;
17
18
use Cilex\Application;
19
use phpDocumentor\Plugin\Core\Transformer\Writer;
20
use phpDocumentor\Transformer\Router\Queue;
21
use phpDocumentor\Transformer\Writer\Collection;
22
use Pimple\Container;
23
use Pimple\ServiceProviderInterface;
24
25
/**
26
 * Register all services and subservices necessary to get phpDocumentor up and running.
27
 *
28
 * This provider exposes no services of its own but populates the Writer Collection with the basic writers for
29
 * phpDocumentor and, for backwards compatibility, registers the service providers for Graphs, Twig and PDF to
30
 * the container.
31
 */
32
final class ServiceProvider implements ServiceProviderInterface
33
{
34
    /**
35
     * Registers services on the given app.
36
     *
37
     * @param Container $app An Application instance.
38
     */
39 1
    public function register(Container $app): void
40
    {
41 1
        $this->registerWriters($app);
0 ignored issues
show
$app of type object<Pimple\Container> is not a sub-type of object<Cilex\Application>. It seems like you assume a child class of the class Pimple\Container 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...
42 1
        $this->registerDependenciesOnXsltExtension($app);
0 ignored issues
show
$app of type object<Pimple\Container> is not a sub-type of object<Cilex\Application>. It seems like you assume a child class of the class Pimple\Container 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...
43
44 1
        $app->register(new \phpDocumentor\Plugin\Graphs\ServiceProvider());
45 1
        $app->register(new \phpDocumentor\Plugin\Twig\ServiceProvider());
46 1
    }
47
48
    /**
49
     * Creates all writers for this plugin and adds them to the WriterCollection object.
50
     *
51
     * This action will enable transformations in templates to make use of these writers.
52
     */
53 1
    private function registerWriters(Application $app)
54
    {
55 1
        $writerCollection = $this->getWriterCollection($app);
56
57 1
        $writerCollection['FileIo'] = new Writer\FileIo();
58 1
        $writerCollection['sourcecode'] = new Writer\Sourcecode();
59 1
        $writerCollection['statistics'] = new Writer\Statistics();
60 1
        $writerCollection['xsl'] = new Writer\Xsl($app['monolog']);
61
62 1
        $checkstyleWriter = new Writer\Checkstyle();
63 1
        $writerCollection['checkstyle'] = $checkstyleWriter;
64
65 1
        $xmlWriter =  new Writer\Xml($app['transformer.routing.standard']);
66 1
        $writerCollection['xml'] = $xmlWriter;
67 1
    }
68
69
    /**
70
     * Registers the Routing Queue and Descriptor Builder objects on the XSLT Extension class.
71
     *
72
     * In every template we use PHP helpers in order to be able to have routing that is universal between templates and
73
     * convert Markdown text into HTML (for example). The only way for XSL to do this is by having global functions or
74
     * static methods in a class because you cannot inject an object into an XSL processor.
75
     *
76
     * With this method we make sure that all dependencies used by the static methods are injected as static properties.
77
     */
78 1
    private function registerDependenciesOnXsltExtension(Application $app)
79
    {
80 1
        $queue = new Queue();
81 1
        $queue->insert($app['transformer.routing.standard'], 1);
82 1
        Xslt\Extension::$routers = $queue;
83 1
        Xslt\Extension::$descriptorBuilder = $app['descriptor.builder'];
84 1
    }
85
86
    /**
87
     * Returns the WriterCollection service from the Service Locator.
88
     *
89
     * @return Collection
90
     */
91 1
    private function getWriterCollection(Application $app)
92
    {
93 1
        return $app['transformer.writer.collection'];
94
    }
95
}
96