GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TarTask   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
B configureVariables() 0 28 1
A getFiles() 0 12 4
B execute() 0 24 4
1
<?php
2
/**
3
 * See class comment
4
 *
5
 * PHP Version 5
6
 *
7
 * @category   Netresearch
8
 * @package    Netresearch\Kite
9
 * @subpackage Task
10
 * @author     Christian Opitz <[email protected]>
11
 * @license    http://www.netresearch.de Netresearch Copyright
12
 * @link       http://www.netresearch.de
13
 */
14
15
namespace Netresearch\Kite\Task;
16
17
/**
18
 * Create a tar archive a set of files
19
 *
20
 * @category   Netresearch
21
 * @package    Netresearch\Kite
22
 * @subpackage Task
23
 * @author     Christian Opitz <[email protected]>
24
 * @license    http://www.netresearch.de Netresearch Copyright
25
 * @link       http://www.netresearch.de
26
 */
27
class TarTask extends \Netresearch\Kite\Task
28
{
29
    /**
30
     * Configure the options
31
     *
32
     * @return array
33
     */
34
    protected function configureVariables()
35
    {
36
        return array(
37
            'command' => array(
38
                'type' => 'string',
39
                'label' => 'Name of the task',
40
                'required' => true,
41
            ),
42
            'cwd' => array(
43
                'type' => 'string',
44
                'label' => 'The directory to change to before running the command'
45
            ),
46
            'options' => array(
47
                'type' => 'array',
48
                'default' => array(),
49
                'label' => 'Array with options: Elements with numeric keys or bool true values will be --switches.'
50
            ),
51
            'arguments' => array(
52
                'type' => 'array',
53
                'default' => array(),
54
                'label' => 'Arguments to pass to the cmd'
55
            ),
56
            'optArg' => array(
57
                'type' => 'array',
58
                'label' => 'Arguments and options in one array. Elements with numeric keys will be arguments, elems. with bool true values will be --switches, all other options'
59
            )
60
        ) + parent::configureVariables();
61
    }
62
63
    /**
64
     * Get the files
65
     *
66
     * @return array|mixed
67
     */
68
    protected function getFiles()
69
    {
70
        $files = $this->get('files');
71
        if (is_string($files)) {
72
            $files = array_filter(preg_split('#[\n' . PATH_SEPARATOR . ',]#', $files));
73
        }
74
        if (!is_array($files) && !$files instanceof \Traversable) {
75
            throw new \Netresearch\Kite\Exception('files must be traversable');
76
        }
77
78
        return $files;
79
    }
80
81
    /**
82
     * Execute the task
83
     *
84
     * @return void
85
     */
86
    public function execute()
87
    {
88
        $filesystem = $this->console->getFilesystem();
89
        $dir = dirname($this->get('toFile'));
90
        $filesystem->ensureDirectoryExists($dir);
91
        $cmd = 'tar -rf ' . escapeshellarg($this->get('toFile')) . ' ';
92
93
        if ($this->get('tmpCopy', true)) {
94
            $tmpFolder = basename($this->get('toFile')) . '-' . uniqid();
95
            $filesystem->ensureDirectoryExists($tmpFolder);
96
97
            foreach ($this->getFiles() as $file) {
98
                $filesystem->copy($file, $tmpFolder . '/' . $file);
99
            }
100
101
            $this->console->createProcess($cmd . ' -C ' . escapeshellarg($tmpFolder) . ' .')->run();
102
103
            $filesystem->remove($tmpFolder);
104
        } else {
105
            foreach ($this->getFiles() as $file) {
106
                $this->console->createProcess($cmd . escapeshellarg($file))->run();
107
            }
108
        }
109
    }
110
}
111
?>
112