Issues (462)

src/helpers/ClassHelper.php (18 issues)

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
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 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\units\helpers;
12
13
use Craft;
14
use ReflectionClass;
15
use ReflectionException;
16
use function dirname;
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   Units
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
21
 * @since     1.0.0
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 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
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