Completed
Push — develop ( 80740b...61b5c3 )
by Mike
10:20
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
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\Partials;
17
18
use Parsedown;
19
use phpDocumentor\Descriptor\Collection;
20
use phpDocumentor\Partials\Exception\MissingNameForPartialException;
21
use Pimple\Container;
22
use Pimple\ServiceProviderInterface;
23
24
/**
25
 * This provider is responsible for registering the partials component with the given Application.
26
 */
27
class ServiceProvider implements ServiceProviderInterface
28
{
29
    /**
30
     * Registers services on the given app.
31
     *
32
     * @throws MissingNameForPartialException if a partial has no name provided.
33
     */
34
    public function register(Container $app): void
35
    {
36
        $app['markdown'] = function () {
37
            return Parsedown::instance();
38
        };
39
40
        $partialsCollection = new Collection();
41
        $app['partials'] = $partialsCollection;
42
43
        /** @var Partial[] $partials */
44
        $partials = []; //$config->getPartials();
45
        if ($partials) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $partials of type phpDocumentor\Partials\Partial[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
46
            foreach ($partials as $partial) {
47
                if (! $partial->getName()) {
48
                    throw new MissingNameForPartialException('The name of the partial to load is missing');
49
                }
50
51
                $partial->setParser($app['markdown']);
52
                if (!$partial->getContent() && $partial->getLink()) {
53
                    if (! is_readable($partial->getLink())) {
54
                        $app['monolog']->error(
55
                            sprintf('Partial "%s" not readable or found.', $partial->getLink())
56
                        );
57
                        continue;
58
                    }
59
                }
60
61
                $partialsCollection->set($partial->getName(), $partial);
62
            }
63
        }
64
    }
65
}
66