Completed
Push — master ( 8a5482...34c135 )
by Robert
13:32 queued 11:17
created

Products::show()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 4.0016

Importance

Changes 7
Bugs 2 Features 2
Metric Value
c 7
b 2
f 2
dl 0
loc 31
ccs 20
cts 21
cp 0.9524
rs 8.5806
cc 4
eloc 18
nc 1
nop 2
crap 4.0016
1
<?php
2
3
namespace Rs\VersionEye\Output;
4
5
use Symfony\Component\Console\Output\OutputInterface;
6
7
/**
8
 * Products.
9
 *
10
 * @author Robert Schönthal <[email protected]>
11
 */
12
class Products extends BaseOutput
13
{
14
    /**
15
     * output for the search API.
16
     *
17
     * @param OutputInterface $output
18
     * @param array           $response
19
     */
20 1
    public function search(OutputInterface $output, array $response)
21
    {
22 1
        $this->printProducts($output, $response['results']);
23 1
    }
24
25
    /**
26
     * output for the references API.
27
     *
28
     * @param OutputInterface $output
29
     * @param array           $response
30
     */
31 1
    public function references(OutputInterface $output, array $response)
32
    {
33 1
        $this->printProducts($output, $response['results']);
34 1
    }
35
36
    /**
37
     * output for the show API.
38
     *
39
     * @param OutputInterface $output
40
     * @param array           $response
41
     */
42 1
    public function show(OutputInterface $output, array $response)
43
    {
44 1
        $this->printList($output,
45 1
            ['Name', 'Description', 'Source', 'Archive', 'Key', 'Type', 'License', 'Version', 'Group', 'Updated At'],
46 1
            ['name', 'description', 'links', 'archives', 'prod_key', 'prod_type', 'license_info', 'version', 'group_id', 'updated_at'],
47 1
            $response,
48
            function ($heading, $value) {
49 1
                if ('Source' === $heading) {
50
                    $value = array_filter($value, function ($link) {
51 1
                        return 'Source' === $link['name'];
52 1
                    });
53
54 1
                    if (!empty($value)) {
55 1
                        return array_pop($value)['link'];
56
                    }
57
                }
58
59 1
                if ('Archive' === $heading) {
60 1
                    return array_pop($value)['link'];
61
                }
62
63 1
                return $value;
64
            }
65 1
        );
66
67 1
        $this->printTable($output,
68 1
            ['Name', 'Current', 'Requested'],
69 1
            ['name', 'parsed_version', 'version'],
70 1
            $response['dependencies']
71 1
        );
72 1
    }
73
74
    /**
75
     * output for the follow status API.
76
     *
77
     * @param OutputInterface $output
78
     * @param array           $response
79
     */
80 1
    public function followStatus(OutputInterface $output, array $response)
81
    {
82 1
        $this->printBoolean($output, 'YES', 'NO', true === $response['follows']);
83 1
    }
84
85
    /**
86
     * output for the follow API.
87
     *
88
     * @param OutputInterface $output
89
     * @param array           $response
90
     */
91 1
    public function follow(OutputInterface $output, array $response)
92
    {
93 1
        $this->printBoolean($output, 'OK', 'FAIL', true === $response['follows']);
94 1
    }
95
96
    /**
97
     * output for the unfollow API.
98
     *
99
     * @param OutputInterface $output
100
     * @param array           $response
101
     */
102 1
    public function unfollow(OutputInterface $output, array $response)
103
    {
104 1
        $this->printBoolean($output, 'OK', 'FAIL', false === $response['follows']);
105 1
    }
106
107
    /**
108
     * output for the versions API.
109
     *
110
     * @param OutputInterface $output
111
     * @param array           $response
112
     */
113 1
    public function versions(OutputInterface $output, array $response)
114
    {
115 1
        $this->printList($output,
116 1
            ['Name', 'Language', 'Key', 'Type', 'Version'],
117 1
            ['name', 'language', 'prod_key', 'prod_type', 'version'],
118
            $response
119 1
        );
120
121 1
        $this->printTable($output,
122 1
            ['Version', 'Released At'],
123 1
            ['version', 'released_at'],
124 1
            $response['versions'],
125 1
            function ($key, $value) {
126 1
                if ('released_at' !== $key) {
127 1
                    return $value;
128
                }
129
130 1
                return date('Y-m-d H:i:s', strtotime($value));
131
            }
132 1
        );
133 1
    }
134
}
135