Completed
Push — develop ( 8fda15...dbbcf5 )
by Jaap
14s
created

src/phpDocumentor/Partials/ServiceProvider.php (1 issue)

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\Partials;
13
14
use Cilex\Application;
15
use phpDocumentor\Configuration as ApplicationConfiguration;
16
use phpDocumentor\Partials\Collection as PartialsCollection;
17
use phpDocumentor\Translator\Translator;
18
use Pimple\Container;
19
use Pimple\ServiceProviderInterface;
20
21
/**
22
 * This provider is responsible for registering the partials component with the given Application.
23
 */
24
class ServiceProvider implements ServiceProviderInterface
25
{
26
    /**
27
     * Registers services on the given app.
28
     *
29
     * @param Application $app An Application instance
30
     *
31
     * @throws Exception\MissingNameForPartialException if a partial has no name provided.
32
     */
33
    public function register(Container $app)
34
    {
35
        /** @var Translator $translator */
36
        $translator = $app['translator'];
37
        $translator->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages');
38
39
        /** @var ApplicationConfiguration $config */
40
        $config = $app['config'];
41
42
        $app['markdown'] = function () {
43
            return \Parsedown::instance();
44
        };
45
46
        $partialsCollection = new PartialsCollection($app['markdown']);
47
        $app['partials'] = $partialsCollection;
48
49
        /** @var Partial[] $partials */
50
        $partials = []; //$config->getPartials();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
        if ($partials) {
52
            foreach ($partials as $partial) {
53
                if (! $partial->getName()) {
54
                    throw new Exception\MissingNameForPartialException('The name of the partial to load is missing');
55
                }
56
57
                $content = '';
58
                if ($partial->getContent()) {
59
                    $content = $partial->getContent();
60
                } elseif ($partial->getLink()) {
61
                    if (! is_readable($partial->getLink())) {
62
                        $app['monolog']->error(
63
                            sprintf($translator->translate('PPCPP:EXC-NOPARTIAL'), $partial->getLink())
64
                        );
65
                        continue;
66
                    }
67
68
                    $content = file_get_contents($partial->getLink());
69
                }
70
71
                $partialsCollection->set($partial->getName(), $content);
72
            }
73
        }
74
    }
75
}
76