BasedOnVars::getVars()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0023

Importance

Changes 0
Metric Value
dl 0
loc 21
c 0
b 0
f 0
rs 9.3142
ccs 11
cts 12
cp 0.9167
cc 2
eloc 13
nc 2
nop 0
crap 2.0023
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the skeleton package.
7
 *
8
 * (c) Gennady Knyazkin <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Gennadyx\Skeleton\VarSource;
15
16
use Stringy\StaticStringy;
17
18
/**
19
 * Class BasedOnVars
20
 *
21
 * @author Gennady Knyazkin <[email protected]>
22
 */
23
class BasedOnVars extends AbstractSource
24
{
25
    /**
26
     * @inheritDoc
27
     */
28 2
    protected function find(string $name)
29
    {
30 2
        $vars = $this->getVars();
31
32 2
        if (isset($vars[$name]) && !empty($vars[$name])) {
33 2
            return $vars[$name];
34
        }
35
36
        return null;
37
    }
38
39
    /**
40
     * @return array
41
     */
42 2
    protected function getVars(): array
43
    {
44 2
        $defined = static::vars();
45
46 2
        if (!isset($defined['name'], $defined['vendor'])) {
47
            return [];
48
        }
49
50
        $vars    = [
51 2
            'description'     => sprintf('%s composer package', $defined['name']),
52 2
            'author_homepage' => sprintf('https://github.com/%s', $defined['vendor']),
53 2
            'namespace'       => sprintf(
54 2
                '%s\\\%s',
55 2
                ...array_map([StaticStringy::class, 'upperCamelize'], [$defined['vendor'], $defined['name']])
56
            )
57
        ];
58 2
        $vars['homepage']        = sprintf('https://github.com/%s/%s', $defined['vendor'], $defined['name']);
59 2
        $vars['tests_namespace'] = sprintf('%s\\\Tests', $vars['namespace']);
60
61 2
        return $vars;
62
    }
63
}
64