Completed
Push — prototype ( 3bfdd7...aec713 )
by Peter
07:47
created

Credits::getCredits()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 5
nop 1
dl 0
loc 21
rs 8.7624
c 0
b 0
f 0
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoAppLib\Service;
12
13
use WebinoBaseLib\Iterator\RecursiveDirectoryRegexIterator;
14
15
/**
16
 * Class Credits
17
 */
18
class Credits
19
{
20
    const VENDOR_COPYRIGHT = 'Copyright (c) 2015-2017 Webino, s.r.o.';
21
    const VENDOR_URL       = 'http://webino.sk';
22
    const AUTHOR_NAME      = 'Peter Bačinský';
23
    const AUTHOR_URL       = 'http://bacinsky.sk';
24
25
    /**
26
     * Returns parsed LICENSE info from vendor dir
27
     *
28
     * @param string $dir Vendor dir
29
     * @return array
30
     */
31
    public function getCredits($dir)
32
    {
33
        $credits = [];
34
35
        /** @var \SplFileInfo $file */
36
        foreach (new RecursiveDirectoryRegexIterator($dir, '/license.?.*$/i') as $file) {
37
            foreach (file($file->getPathname()) as $line) {
38
                if (0 === strpos($line, 'Copyright (c)')) {
39
40
                    $vendor  = basename(dirname($file->getPath()));
41
                    $package = basename($file->getPath());
42
                    $name    = ($vendor === 'vendor') ? $package : "$vendor/$package";
43
44
                    $credits[$name] = [$name, $line];
45
                }
46
            }
47
        }
48
49
        asort($credits);
50
        return $credits;
51
    }
52
}
53