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

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

Check for implicit conversion of array to boolean.

Best Practice Bug Minor

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;
17
18
use Pimple\Container;
19
use Pimple\ServiceProviderInterface;
20
use RuntimeException;
21
22
class ServiceProvider implements ServiceProviderInterface
23
{
24
    public function register(Container $app): void
25
    {
26
        $plugins = [];
27
28
        if (! $plugins) {
0 ignored issues
show
Bug Best Practice introduced by Mike van Riel
The expression $plugins of type array 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...
29
            $app->register(new Core\ServiceProvider());
30
            $app->register(new Scrybe\ServiceProvider());
31
32
            return;
33
        }
34
35
        array_walk(
36
            $plugins,
37
            function ($plugin) use ($app) {
38
                /** @var Plugin $plugin */
39
                $provider = (strpos($plugin->getClassName(), '\\') === false)
40
                    ? sprintf('phpDocumentor\\Plugin\\%s\\ServiceProvider', $plugin->getClassName())
41
                    : $plugin->getClassName();
42
                if (!class_exists($provider)) {
43
                    throw new RuntimeException('Loading Service Provider for ' . $provider . ' failed.');
44
                }
45
46
                try {
47
                    $app->register(new $provider($plugin));
48
                } catch (\InvalidArgumentException $e) {
49
                    throw new RuntimeException($e->getMessage());
50
                }
51
            }
52
        );
53
    }
54
}
55