Completed
Push — master ( 629b98...606f80 )
by Brian
11:50
created

FilesTrait::getClassFromFile()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 8.8571
cc 5
eloc 5
nc 3
nop 1
crap 30
1
<?php
2
3
/*
4
 * This file is part of Laravel Service Provider.
5
 *
6
 * (c) DraperStudio <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace DraperStudio\ServiceProvider;
13
14
trait FilesTrait
15
{
16
    /**
17
     * @param $file
18
     *
19
     * @return string
20
     */
21
    protected function getFileName($file)
22
    {
23
        $file = basename($file);
24
25
        if (!ends_with($file, '.php')) {
26
            $file = $file.'.php';
27
        }
28
29
        return $file;
30
    }
31
32
    /**
33
     * Get the target destination path for the files.
34
     *
35
     * @param string $package
0 ignored issues
show
Bug introduced by
There is no parameter named $package. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
36
     *
37
     * @return string
38
     */
39
    protected function getDestinationPath($type, $args)
40
    {
41
        return vsprintf($this->paths[$type]['dest'], $args);
0 ignored issues
show
Bug introduced by
The property paths does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
    }
43
44
    /**
45
     * @param $type
46
     * @param $files
47
     *
48
     * @return array
49
     */
50
    protected function getSourceFiles($path)
51
    {
52
        $files = [];
53
        foreach (glob($path.'/*.php') as $file) {
54
            $files[] = $file;
55
        }
56
57
        return $files;
58
    }
59
60
    /**
61
     * @param $path
62
     *
63
     * @return mixed
64
     */
65
    protected function getClassFromFile($path)
66
    {
67
        $count = count($tokens = token_get_all(file_get_contents($path)));
68
69
        for ($i = 2; $i < $count; ++$i) {
70
            if ($tokens[$i - 2][0] == T_CLASS && $tokens[$i - 1][0] == T_WHITESPACE && $tokens[$i][0] == T_STRING) {
71
                return $tokens[$i][1];
72
            }
73
        }
74
    }
75
}
76