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 — v0.89-develop ( 9799ea...0ad74a )
by Zordius
03:45
created

LightnCandy   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 86.49%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 17
c 6
b 0
f 0
lcom 1
cbo 3
dl 0
loc 108
ccs 32
cts 37
cp 0.8649
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A compile() 0 18 3
A getContext() 0 3 1
A handleError() 0 14 4
D prepare() 0 29 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
26
/**
27
 * LightnCandy major static class
28
 */
29
class LightnCandy extends Flags
30
{
31
    protected static $lastContext;
32
    public static $lastParsed;
33
34
    /**
35
     * Compile handlebars template into PHP code.
36
     *
37
     * @param string $template handlebars template string
38
     * @param array<string,array|string|integer> $options LightnCandy compile time and run time options, default is array('flags' => LightnCandy::FLAG_BESTPERFORMANCE)
39
     *
40
     * @return string|false Compiled PHP code when successed. If error happened and compile failed, return false.
41
     */
42 642
    public static function compile($template, $options = array('flags' => self::FLAG_BESTPERFORMANCE)) {
43 642
        $context = Context::create($options);
44
45 642
        if (static::handleError($context)) {
46 2
            return false;
47
        }
48
49 640
        $code = Compiler::compileTemplate($context, $template);
50 640
        static::$lastParsed = Compiler::$lastParsed;
51
52
        // return false when fatal error
53 640
        if (static::handleError($context)) {
54 57
            return false;
55
        }
56
57
        // Or, return full PHP render codes as string
58 575
        return Compiler::composePHPRender($context, $code);
59
    }
60
61
    /**
62
     * Handle exists error and return error status.
63
     *
64
     * @param array<string,array|string|integer> $context Current context of compiler progress.
65
     *
66
     * @throws \Exception
67
     * @return boolean True when error detected
68
     *
69
     * @expect false when input array('error' => array())
70
     * @expect true when input array('error' => array('some error'), 'flags' => array('errorlog' => 0, 'exception' => 0))
71
     */
72 643
    protected static function handleError(&$context) {
73 643
        static::$lastContext = $context;
74
75 643
        if (count($context['error'])) {
76 68
            if ($context['flags']['errorlog']) {
77 1
                error_log(implode("\n", $context['error']));
78
            }
79 68
            if ($context['flags']['exception']) {
80 8
                throw new \Exception(implode("\n", $context['error']));
81
            }
82 60
            return true;
83
        }
84 641
        return false;
85
    }
86
87
    /**
88
     * Get last compiler context.
89
     *
90
     * @return array<string,array|string|integer> Context data
91
     */
92 211
    public static function getContext() {
93 211
        return static::$lastContext;
94
    }
95
96
    /**
97
     * 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.
98
     *
99
     * @param string      $php PHP code
100
     * @param string|null $tmpDir Optional, change temp directory for php include file saved by prepare() when cannot include PHP code with data:// format.
101
     * @param boolean     $delete Optional, delete temp php file when set to tru. Default is true, set it to false for debug propose
102
     *
103
     * @return Closure|false result of include()
104
     *
105
     * @deprecated
106
     */
107 545
    public static function prepare($php, $tmpDir = null, $delete = true) {
108 545
        if (!ini_get('allow_url_include') || !ini_get('allow_url_fopen')) {
109 545
            if (!is_string($tmpDir) || !is_dir($tmpDir)) {
110 545
                $tmpDir = sys_get_temp_dir();
111
            }
112
        }
113
114 545
        if (is_dir($tmpDir)) {
115 545
            $fn = tempnam($tmpDir, 'lci_');
116 545
            if (!$fn) {
117
                error_log("Can not generate tmp file under $tmpDir!!\n");
118
                return false;
119
            }
120 545
            if (!file_put_contents($fn, $php)) {
121
                error_log("Can not include saved temp php code from $fn, you should add $tmpDir into open_basedir!!\n");
122
                return false;
123
            }
124
125 545
            $phpfunc = include($fn);
126
127 545
            if ($delete) {
128 545
                unlink($fn);
129
            }
130
131 545
            return $phpfunc;
132
        }
133
134
        return include('data://text/plain,' . urlencode($php));
135
    }
136
}
137
138