Issues (208)

src/helpers/PluginConfig.php (24 issues)

1
<?php
2
/**
3
 * Vite plugin for Craft CMS
4
 *
5
 * Allows the use of the Vite.js next generation frontend tooling with Craft CMS
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2022 nystudio107
0 ignored issues
show
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\vite\helpers;
12
13
use Craft;
14
use ReflectionClass;
15
use ReflectionException;
16
use ReflectionProperty;
17
18
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
19
 * @author    nystudio107
0 ignored issues
show
The tag in position 1 should be the @package tag
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
20
 * @package   Vite
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
21
 * @since     4.0.3
0 ignored issues
show
The tag in position 3 should be the @author tag
Loading history...
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
22
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
23
class PluginConfig
24
{
25
    // Public static methods
26
    // =========================================================================
27
28
    /**
29
     * Return a service config definition pre-populated with settings from the
30
     * $configHandle config/ file
31
     *
32
     * @param string $configHandle
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
33
     * @param string $serviceClass
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
34
     * @return array
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
35
     */
36
    public static function serviceDefinitionFromConfig(string $configHandle, string $serviceClass): array
37
    {
38
        $serviceAttrs = [];
0 ignored issues
show
The assignment to $serviceAttrs is dead and can be removed.
Loading history...
39
        // Get the available attributes from the $serviceClass
40
        try {
41
            $serviceAttrs = self::getClassAttributes($serviceClass);
42
        } catch (ReflectionException $e) {
43
            // That's fine
44
        }
45
        // Intersect the settings from the config file with the available service attributes
46
        $serviceConfig = array_intersect_key(
47
            Craft::$app->getConfig()->getConfigFromFile($configHandle),
48
            $serviceAttrs
49
        );
50
51
        return array_merge(
52
            $serviceConfig,
53
            ['class' => $serviceClass]
54
        );
55
    }
56
57
    /**
0 ignored issues
show
Parameter $className should have a doc-comment as per coding-style.
Loading history...
58
     * Return the list of attribute names from a class name
59
     *
60
     * @return array list of attribute names.
61
     * @throws ReflectionException
62
     */
63
    public static function getClassAttributes(string $className): array
64
    {
65
        $class = new ReflectionClass($className);
66
        $names = [];
67
        foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
68
            if (!$property->isStatic()) {
69
                $name = $property->getName();
70
                $names[$name] = $name;
71
            }
72
        }
73
74
        return $names;
75
    }
76
}
77