DynamicStub::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 4
crap 2
1
<?php
2
/**
3
 * For licensing information, please see the LICENSE file accompanied with this file.
4
 *
5
 * @author Gerard van Helden <[email protected]>
6
 * @copyright 2012 Gerard van Helden <http://melp.nl>
7
 */
8
namespace Zicht\Tool\Packager\Node;
9
10
use Zicht\Tool\Script\Buffer;
11
12
/**
13
 * PHAR stub for a dynamic Z build
14
 */
15
class DynamicStub extends Stub
16
{
17
    /**
18
     * Construct the stub with the specified details
19
     *
20
     * @param \Phar $phar
21
     * @param string $appName
22
     * @param string $appVersion
23
     * @param string $configFileName
24
     */
25
    public function __construct(\Phar $phar, $appName, $appVersion, $configFileName)
26
    {
27
        parent::__construct($phar, $appName, $appVersion);
28
        $this->configFilename = $configFileName;
0 ignored issues
show
Bug introduced by
The property configFilename does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
    }
30
31
32
    /**
33
     * Writes the initialization code for a dynamic build
34
     *
35
     * @param \Zicht\Tool\Script\Buffer $buffer
36
     * @return void
37
     */
38
    protected function compileInitialization(Buffer $buffer)
39
    {
40
        $buffer->write('$app = new Zicht\Tool\Application(')
41
            ->asPhp($this->appName)
42
            ->raw(', Zicht\Version\Version::fromString(')
43
            ->asPhp($this->appVersion)
44
            ->raw(') ?: new Zicht\Version\Version(), Zicht\Tool\Configuration\ConfigurationLoader::fromEnv(')->asPhp($this->configFilename)->raw(')')
45
            ->raw(');')
46
            ->eol();
47
    }
48
}
49