SetupPyController   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 40%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 18
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 66
ccs 14
cts 35
cp 0.4
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A actionLoad() 0 21 3
A getUrl() 0 4 2
A getName() 0 4 2
A getVersion() 0 4 2
A getLicense() 0 4 2
A getPackages() 0 4 2
A getAuthorData() 0 4 1
A getAuthor() 0 4 2
A getAuthorEmail() 0 4 2
1
<?php
2
3
/*
4
 * PyPI plugin for HiDev
5
 *
6
 * @link      https://github.com/hiqdev/hidev-pypi
7
 * @package   hidev-pypi
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\pypi\controllers;
13
14
/**
15
 * Goal for `setup.py` file.
16
 */
17
class SetupPyController extends \hidev\controllers\FileController
18
{
19
    protected $_file = 'setup.py';
20
21
    public function actionLoad()
22
    {
23
        parent::actionLoad();
24
        $sets = [
25
            'name'          => $this->getName(),
26
            'packages'      => $this->getPackages(),
27
            'version'       => $this->getVersion(),
28
            'license'       => $this->getLicense(),
29
            'description'   => $this->takePackage()->title,
30
            'keywords'      => $this->takePackage()->keywords,
31
            'url'           => $this->getUrl(),
32
            'author'        => $this->getAuthor(),
33
            'author_email'  => $this->getAuthorEmail(),
34
        ];
35
        $this->setItems($sets, 'first');
36
        foreach ($sets as $k => $v) {
37
            if (!$this->get($k)) {
38
                $this->delete($k);
39
            }
40
        }
41
    }
42
43 1
    public function getUrl()
44
    {
45 1
        return $this->rawItem('url') ?: $this->takePackage()->homepage;
46
    }
47
48 2
    public function getName()
49
    {
50 2
        return $this->getItem('name') ?: $this->takePackage()->name;
51
    }
52
53 1
    public function getVersion()
54
    {
55 1
        return $this->getItem('version') ?: $this->takePackage()->getVersion();
56
    }
57
58 1
    public function getLicense()
59
    {
60 1
        return $this->getItem('license') ?: $this->takePackage()->getLicense();
61
    }
62
63 1
    public function getPackages()
64
    {
65 1
        return $this->getItem('packages') ?: $this->getName();
66
    }
67
68
    public function getAuthorData($field)
69
    {
70
        return reset($this->takePackage()->authors)[$field];
71
    }
72
73 1
    public function getAuthor()
74
    {
75 1
        return $this->getItem('author') ?: $this->getAuthorData('name');
76
    }
77
78 1
    public function getAuthorEmail()
79
    {
80 1
        return $this->getItem('author_email') ?: $this->getAuthorData('email');
81
    }
82
}
83