Stub   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 51
ccs 0
cts 19
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A compile() 0 14 1
compileInitialization() 0 1 ?
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
use Zicht\Tool\Script\Node\Node;
12
13
/**
14
 * Phar stub
15
 */
16
abstract class Stub implements Node
17
{
18
    protected $phar;
19
    protected $appName;
20
    protected $appVersion;
21
22
    /**
23
     * Writes the header stub to the phar.
24
     *
25
     * @param \Phar $phar
26
     * @param string $appName
27
     * @param string $appVersion
28
     */
29
    public function __construct(\Phar $phar, $appName, $appVersion)
30
    {
31
        $this->phar = $phar;
32
        $this->appName = $appName;
33
        $this->appVersion = $appVersion;
34
    }
35
36
37
    /**
38
     * Compiles into the specified buffer.
39
     *
40
     * @param \Zicht\Tool\Script\Buffer $buffer
41
     * @return void
42
     */
43
    final public function compile(Buffer $buffer)
44
    {
45
        $buffer
46
            ->writeln("Phar::mapPhar('z.phar');")
47
            ->writeln("define('ZPREFIX', 'phar://z.phar/');")
48
            ->writeln("require_once 'phar://z.phar/vendor/autoload.php';")
49
        ;
50
51
        $this->compileInitialization($buffer);
52
        $buffer
53
            ->writeln('$app->run();')
54
            ->writeln('__HALT_COMPILER();')
55
        ;
56
    }
57
58
59
    /**
60
     * Should compile the initialization code into the buffer.
61
     *
62
     * @param \Zicht\Tool\Script\Buffer $buffer
63
     * @return void
64
     */
65
    abstract protected function compileInitialization(Buffer $buffer);
66
}
67