Unix::prepareConfigOpts()   C
last analyzed

Complexity

Conditions 13
Paths 9

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 22
rs 6.6166
cc 13
nc 9
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * Pickle
5
 *
6
 *
7
 * @license
8
 *
9
 * New BSD License
10
 *
11
 * Copyright © 2015-2015, Pickle community. All rights reserved.
12
 *
13
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15
 *     * Redistributions of source code must retain the above copyright
16
 *       notice, this list of conditions and the following disclaimer.
17
 *     * Redistributions in binary form must reproduce the above copyright
18
 *       notice, this list of conditions and the following disclaimer in the
19
 *       documentation and/or other materials provided with the distribution.
20
 *     * Neither the name of the Hoa nor the names of its contributors may be
21
 *       used to endorse or promote products derived from this software without
22
 *       specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
 * POSSIBILITY OF SUCH DAMAGE.
35
 */
36
37
namespace Pickle\Package\PHP\Command\Build;
38
39
use Exception;
40
use Pickle\Base\Abstracts;
41
use Pickle\Base\Interfaces;
42
43
class Unix extends Abstracts\Package\Build implements Interfaces\Package\Build
44
{
45
    public function prepare()
46
    {
47
        $this->phpize();
48
    }
49
50
    public function phpize()
51
    {
52
        $backCwd = getcwd();
53
        chdir($this->pkg->getSourceDir());
54
55
        $res = $this->runCommand('phpize');
56
        chdir($backCwd);
57
        if (!$res) {
58
            throw new Exception('phpize failed');
59
        }
60
    }
61
62
    public function configure($opts = null)
63
    {
64
        $backCwd = getcwd();
65
        chdir($this->tempDir);
66
67
        $configureOptions = $opts ?: $this->prepareConfigOpts();
68
69
        $res = $this->runCommand($this->pkg->getSourceDir() . '/configure ' . $configureOptions);
70
        chdir($backCwd);
71
        if (!$res) {
72
            throw new Exception('configure failed, see log at ' . $this->tempDir . '\config.log');
73
        }
74
    }
75
76
    public function make()
77
    {
78
        $backCwd = getcwd();
79
        chdir($this->tempDir);
80
        $res = $this->runCommand('make');
81
        chdir($backCwd);
82
83
        if (!$res) {
84
            throw new Exception('make failed');
85
        }
86
    }
87
88
    public function install()
89
    {
90
        $backCwd = getcwd();
91
        chdir($this->tempDir);
92
        $res = $this->runCommand('make install');
93
        chdir($backCwd);
94
        if (!$res) {
95
            throw new Exception('make install failed');
96
        }
97
    }
98
99
    public function getInfo()
100
    {
101
        return [];
102
    }
103
104
    protected function prepareConfigOpts()
105
    {
106
        $configureOptions = '';
107
        foreach ($this->options as $name => $option) {
108
            if ($option->type === 'enable') {
109
                $option->input === true ? 'enable' : 'disable';
110
            } elseif ($option->type == 'disable') {
111
                $option->input === false ? 'enable' : 'disable';
112
            } elseif ($option->type === 'with') {
113
                if ($option->input == 'yes' || $option->input == '1' || $option->type === true) {
114
                    $configureOptions .= ' --with-' . $name;
115
                } elseif ($option->input == 'no' || $option->input == '0' || $option->type === false) {
116
                    $configureOptions .= ' --without-' . $name;
117
                } else {
118
                    $configureOptions .= ' --with-' . $name . '=' . $option->input;
119
                }
120
            }
121
        }
122
123
        $this->appendPkgConfigureOptions($configureOptions);
124
125
        return $configureOptions;
126
    }
127
}
128
129
/* vim: set tabstop=4 shiftwidth=4 expandtab: fdm=marker */
130