BasedOnVars   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 41
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getVars() 0 21 2
A find() 0 10 3
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