ClassHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 2
b 0
f 0
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getClassesInNamespace() 0 21 4
1
<?php
2
/**
3
 * Units plugin for Craft CMS
4
 *
5
 * A plugin for handling physical quantities and the units of measure in which they're represented.
6
 *
7
 * @link      https://nystudio107.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\units\helpers;
12
13
use Craft;
14
use ReflectionClass;
15
use ReflectionException;
16
use function dirname;
17
18
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
19
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
20
 * @package   Units
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
21
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
22
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
23
class ClassHelper
24
{
25
    // Public Static Methods
26
    // =========================================================================
27
28
    /**
29
     * Return an array of classes in the same namespace as $className, in an
30
     * array of shortName => fullyQualifiedName
31
     *
32
     * @param string $className
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
33
     *
34
     * @return array
35
     */
36
    public static function getClassesInNamespace(string $className): array
37
    {
38
        $result = [];
39
        $loader = include Craft::getAlias('@vendor/autoload.php');
40
        $filePath = $loader->findFile($className);
41
        if ($filePath) {
42
            $dir = realpath(dirname($filePath));
43
            $classesMap = ClassMapGenerator::createMap($dir);
44
            foreach ($classesMap as $class => $path) {
45
                try {
46
                    $reflect = new ReflectionClass($class);
47
                    $shortName = $reflect->getShortName();
48
                    $result[$shortName] = $class;
49
                } catch (ReflectionException $e) {
50
                    Craft::error($e->getMessage(), __METHOD__);
51
                }
52
            }
53
        }
54
        ksort($result);
55
56
        return $result;
57
    }
58
}
59