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.
Completed
Push — master ( f24fac...facd84 )
by Zordius
07:29 queued 02:04
created

LightnCandy   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 70.21%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 20
c 3
b 0
f 1
lcom 1
cbo 5
dl 0
loc 136
ccs 33
cts 47
cp 0.7021
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A compile() 0 18 3
A compilePartial() 0 17 3
A handleError() 0 14 4
A getContext() 0 3 1
D prepare() 0 31 9
1
<?php
2
/*
3
4
Copyrights for code authored by Yahoo! Inc. is licensed under the following terms:
5
MIT License
6
Copyright (c) 2013-2015 Yahoo! Inc. All Rights Reserved.
7
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
11
Origin: https://github.com/zordius/lightncandy
12
*/
13
14
/**
15
 * the major file of LightnCandy compiler
16
 *
17
 * @package    LightnCandy
18
 * @author     Zordius <[email protected]>
19
 */
20
21
namespace LightnCandy;
22
23
use \LightnCandy\Context;
24
use \LightnCandy\Compiler;
25
use \LightnCandy\Partial;
26
27
/**
28
 * LightnCandy major static class
29
 */
30
class LightnCandy extends Flags
31
{
32
    protected static $lastContext;
33
    public static $lastParsed;
34
35
    /**
36
     * Compile handlebars template into PHP code.
37
     *
38
     * @param string $template handlebars template string
39
     * @param array<string,array|string|integer> $options LightnCandy compile time and run time options, default is array('flags' => LightnCandy::FLAG_BESTPERFORMANCE)
40
     *
41
     * @return string|false Compiled PHP code when successed. If error happened and compile failed, return false.
42
     */
43 719
    public static function compile($template, $options = array('flags' => self::FLAG_BESTPERFORMANCE)) {
44 719
        $context = Context::create($options);
45
46 719
        if (static::handleError($context)) {
47 2
            return false;
48
        }
49
50 717
        $code = Compiler::compileTemplate($context, SafeString::escapeTemplate($template));
51 717
        static::$lastParsed = Compiler::$lastParsed;
52
53
        // return false when fatal error
54 717
        if (static::handleError($context)) {
55 60
            return false;
56
        }
57
58
        // Or, return full PHP render codes as string
59 647
        return Compiler::composePHPRender($context, $code);
60
    }
61
62
    /**
63
     * Compile handlebars partial into PHP function code.
64
     *
65
     * @param string $template handlebars template string
66
     * @param array<string,array|string|integer> $options LightnCandy compile time and run time options, default is array('flags' => LightnCandy::FLAG_BESTPERFORMANCE)
67
     *
68
     * @return string|false Compiled PHP code when successed. If error happened and compile failed, return false.
69
     */
70
    public static function compilePartial($template, $options = array('flags' => self::FLAG_BESTPERFORMANCE)) {
71
        $context = Context::create($options);
72
73
        if (static::handleError($context)) {
74
            return false;
75
        }
76
77
        $code = Partial::compile($context, $template);
78
        static::$lastParsed = Compiler::$lastParsed;
79
80
        // return false when fatal error
81
        if (static::handleError($context)) {
82
            return false;
83
        }
84
85
        return $code;
86
    }
87
88
    /**
89
     * Handle exists error and return error status.
90
     *
91
     * @param array<string,array|string|integer> $context Current context of compiler progress.
92
     *
93
     * @throws \Exception
94
     * @return boolean True when error detected
95
     *
96
     * @expect false when input array('error' => array())
97
     * @expect true when input array('error' => array('some error'), 'flags' => array('errorlog' => 0, 'exception' => 0))
98
     */
99 720
    protected static function handleError(&$context) {
100 720
        static::$lastContext = $context;
101
102 720
        if (count($context['error'])) {
103 73
            if ($context['flags']['errorlog']) {
104 1
                error_log(implode("\n", $context['error']));
105
            }
106 73
            if ($context['flags']['exception']) {
107 10
                throw new \Exception(implode("\n", $context['error']));
108
            }
109 63
            return true;
110
        }
111 718
        return false;
112
    }
113
114
    /**
115
     * Get last compiler context.
116
     *
117
     * @return array<string,array|string|integer> Context data
118
     */
119 214
    public static function getContext() {
120 214
        return static::$lastContext;
121
    }
122
123
    /**
124
     * Get a working render function by a string of PHP code. This method may requires php setting allow_url_include=1 and allow_url_fopen=1 , or access right to tmp file system.
125
     *
126
     * @param string      $php PHP code
127
     * @param string|null $tmpDir Optional, change temp directory for php include file saved by prepare() when cannot include PHP code with data:// format.
128
     * @param boolean     $delete Optional, delete temp php file when set to tru. Default is true, set it to false for debug propose
129
     *
130
     * @return Closure|false result of include()
131
     *
132
     * @deprecated
133
     */
134 616
    public static function prepare($php, $tmpDir = null, $delete = true) {
135 616
        $php = "<?php $php ?>";
136
137 616
        if (!ini_get('allow_url_include') || !ini_get('allow_url_fopen')) {
138 616
            if (!is_string($tmpDir) || !is_dir($tmpDir)) {
139 616
                $tmpDir = sys_get_temp_dir();
140
            }
141
        }
142
143 616
        if (is_dir($tmpDir)) {
144 616
            $fn = tempnam($tmpDir, 'lci_');
145 616
            if (!$fn) {
146
                error_log("Can not generate tmp file under $tmpDir!!\n");
147
                return false;
148
            }
149 616
            if (!file_put_contents($fn, $php)) {
150
                error_log("Can not include saved temp php code from $fn, you should add $tmpDir into open_basedir!!\n");
151
                return false;
152
            }
153
154 616
            $phpfunc = include($fn);
155
156 616
            if ($delete) {
157 242
                unlink($fn);
158
            }
159
160 616
            return $phpfunc;
161
        }
162
163
        return include('data://text/plain,' . urlencode($php));
164
    }
165
}
166
167