Completed
Push — develop ( a89061...54507c )
by Jaap
08:53
created

src/phpDocumentor/Plugin/Core/ServiceProvider.php (3 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
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Plugin\Core;
13
14
use Cilex\Application;
15
use phpDocumentor\Plugin\Core\Transformer\Writer;
16
use phpDocumentor\Transformer\Writer\Collection;
17
use phpDocumentor\Translator\Translator;
18
use Pimple\Container;
19
use Pimple\ServiceProviderInterface;
20
21
/**
22
 * Register all services and subservices necessary to get phpDocumentor up and running.
23
 *
24
 * This provider exposes no services of its own but populates the Writer Collection with the basic writers for
25
 * phpDocumentor and, for backwards compatibility, registers the service providers for Graphs, Twig and PDF to
26
 * the container.
27
 */
28
final class ServiceProvider implements ServiceProviderInterface
29
{
30
    /**
31
     * Registers services on the given app.
32
     *
33
     * @param Container $app An Application instance.
34
     */
35 1
    public function register(Container $app)
36
    {
37 1
        $this->registerTranslationMessages($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...
38 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...
39 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...
40
41 1
        $app->register(new \phpDocumentor\Plugin\Graphs\ServiceProvider());
42 1
        $app->register(new \phpDocumentor\Plugin\Twig\ServiceProvider());
43 1
    }
44
45
    /**
46
     * Creates all writers for this plugin and adds them to the WriterCollection object.
47
     *
48
     * This action will enable transformations in templates to make use of these writers.
49
     */
50 1
    private function registerWriters(Application $app)
51
    {
52 1
        $writerCollection = $this->getWriterCollection($app);
53
54 1
        $writerCollection['FileIo'] = new Writer\FileIo();
55 1
        $writerCollection['checkstyle'] = new Writer\Checkstyle();
56 1
        $writerCollection['sourcecode'] = new Writer\Sourcecode();
57 1
        $writerCollection['statistics'] = new Writer\Statistics();
58 1
        $writerCollection['xml'] = new Writer\Xml($app['transformer.routing.standard']);
59 1
        $writerCollection['xsl'] = new Writer\Xsl($app['monolog']);
60
61 1
        $writerCollection['checkstyle']->setTranslator($this->getTranslator($app));
62 1
        $writerCollection['xml']->setTranslator($this->getTranslator($app));
63 1
    }
64
65
    /**
66
     * Registers the Messages folder in this plugin as a source of translations.
67
     */
68 1
    private function registerTranslationMessages(Application $app)
69
    {
70 1
        $this->getTranslator($app)->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages');
71 1
    }
72
73
    /**
74
     * Registers the Routing Queue and Descriptor Builder objects on the XSLT Extension class.
75
     *
76
     * In every template we use PHP helpers in order to be able to have routing that is universal between templates and
77
     * convert Markdown text into HTML (for example). The only way for XSL to do this is by having global functions or
78
     * static methods in a class because you cannot inject an object into an XSL processor.
79
     *
80
     * With this method we make sure that all dependencies used by the static methods are injected as static properties.
81
     */
82 1
    private function registerDependenciesOnXsltExtension(Application $app)
83
    {
84 1
        Xslt\Extension::$routers = $app['transformer.routing.queue'];
85 1
        Xslt\Extension::$descriptorBuilder = $app['descriptor.builder'];
86 1
    }
87
88
    /**
89
     * Returns the Translator service from the Service Locator.
90
     *
91
     * @return Translator
92
     */
93 1
    private function getTranslator(Application $app)
94
    {
95 1
        return $app['translator'];
96
    }
97
98
    /**
99
     * Returns the WriterCollection service from the Service Locator.
100
     *
101
     * @return Collection
102
     */
103 1
    private function getWriterCollection(Application $app)
104
    {
105 1
        return $app['transformer.writer.collection'];
106
    }
107
}
108