Passed
Push — master ( 970c56...251b1a )
by Gaetano
09:46
created

pakefile.php (38 issues)

1
<?php
2
/**
3
 * Makefile for phpxmlrpc library.
4
 * To be used with the Pake tool: https://github.com/indeyets/pake/wiki
5
 *
6
 * @copyright (c) 2015-2021 G. Giunta
7
 *
8
 * @todo !important allow user to specify location of docbook xslt instead of the one installed via composer
9
 */
10
11
namespace PhpXmlRpc {
12
13
class Builder
14
{
15
    protected static $buildDir = 'build';
16
    protected static $libVersion;
17
    protected static $tools = array(
18
        'asciidoctor' => 'asciidoctor',
19
        'fop' => 'fop',
20
        'php' => 'php',
21
        'zip' => 'zip',
22
    );
23
    protected static $options = array(
24
        'repo' => 'https://github.com/gggeek/phpxmlrpc',
25
        'branch' => 'master',
26
        'workspace' => null
27
    );
28
29
    public static function libVersion()
30
    {
31
        if (self::$libVersion == null)
32
            throw new \Exception('Missing library version argument');
33
        return self::$libVersion;
34
    }
35
36
    public static function buildDir()
37
    {
38
        return self::$buildDir;
39
    }
40
41
    public static function workspaceDir()
42
    {
43
        return self::option('workspace') != '' ? self::option('workspace') : self::buildDir().'/workspace';
44
    }
45
46
    public static function toolsDir()
47
    {
48
        return self::buildDir().'/tools';
49
    }
50
51
    /// most likely things will break if this one is moved outside of BuildDir
52
    public static function distDir()
53
    {
54
        return self::buildDir().'/xmlrpc-'.self::libVersion();
55
    }
56
57
    /// these will be generated in BuildDir
58
    public static function distFiles()
59
    {
60
        return array(
61
            'xmlrpc-'.self::libVersion().'.tar.gz',
62
            'xmlrpc-'.self::libVersion().'.zip',
63
        );
64
    }
65
66
    public static function getOpts($args=array(), $cliOpts=array())
67
    {
68
        if (count($args) > 0)
69
        //    throw new \Exception('Missing library version argument');
70
            self::$libVersion = $args[0];
71
72
        foreach (self::$tools as $name => $binary) {
73
            if (isset($cliOpts[$name])) {
74
                self::$tools[$name] = $cliOpts[$name];
75
            }
76
        }
77
78
        foreach (self::$options as $name => $value) {
79
            if (isset($cliOpts[$name])) {
80
                self::$options[$name] = $cliOpts[$name];
81
            }
82
        }
83
84
        //pake_echo('---'.self::$libVersion.'---');
85
    }
86
87
    /**
88
     * @param string $name
89
     * @return string
90
     */
91
    public static function tool($name)
92
    {
93
        return self::$tools[$name];
94
    }
95
96
    /**
97
     * @param string $name
98
     * @return string
99
     */
100
    public static function option($name)
101
    {
102
        return self::$options[$name];
103
    }
104
105
    /**
106
     * @param string $inFile
107
     * @param string $xssFile
108
     * @param string $outFileOrDir
109
     * @throws \Exception
110
     */
111
    public static function applyXslt($inFile, $xssFile, $outFileOrDir)
112
    {
113
        if (!file_exists($inFile)) {
114
            throw new \Exception("File $inFile cannot be found");
115
        }
116
        if (!file_exists($xssFile)) {
117
            throw new \Exception("File $xssFile cannot be found");
118
        }
119
120
        $docbookXslPath = realpath(Builder::buildDir().'/tools/vendor/docbook/docbook-xsl/fo/docbook.xsl');
121
        file_put_contents(
122
            $xssFile,
123
            str_replace('%docbook.xsl%', $docbookXslPath, file_get_contents($xssFile))
124
        );
125
126
        // Load the XML source
127
        $xml = new \DOMDocument();
128
        $xml->load($inFile);
129
        $xsl = new \DOMDocument();
130
        $xsl->load($xssFile);
131
132
        // Configure the transformer
133
        $processor = new \XSLTProcessor();
134
        if (version_compare(PHP_VERSION, '5.4', "<")) {
135
            if (defined('XSL_SECPREF_WRITE_FILE')) {
136
                ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
137
            }
138
        } else {
139
            // the php online docs only mention setSecurityPrefs, but somehow some installs have setSecurityPreferences...
140
            if (method_exists('XSLTProcessor', 'setSecurityPrefs')) {
141
                $processor->setSecurityPrefs(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
142
            } else {
143
                $processor->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
0 ignored issues
show
The method setSecurityPreferences() does not exist on XSLTProcessor. Did you maybe mean setSecurityPrefs()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

143
                $processor->/** @scrutinizer ignore-call */ 
144
                            setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
144
            }
145
        }
146
        $processor->importStyleSheet($xsl); // attach the xsl rules
147
148
        if (is_dir($outFileOrDir)) {
149
            if (!$processor->setParameter('', 'base.dir', realpath($outFileOrDir))) {
150
                echo "setting param base.dir KO\n";
151
            }
152
        }
153
154
        $out = $processor->transformToXML($xml);
155
156
        if (!is_dir($outFileOrDir)) {
157
            file_put_contents($outFileOrDir, $out);
158
        }
159
    }
160
161
    public static function highlightPhpInHtml($content)
162
    {
163
        $startTag = '<pre class="programlisting">';
164
        $endTag = '</pre>';
165
166
        //$content = file_get_contents($inFile);
167
        $last = 0;
168
        $out = '';
169
        while (($start = strpos($content, $startTag, $last)) !== false) {
170
            $end = strpos($content, $endTag, $start);
171
            $code = substr($content, $start + strlen($startTag), $end - $start - strlen($startTag));
172
            if ($code[strlen($code) - 1] == "\n") {
173
                $code = substr($code, 0, -1);
174
            }
175
176
            $code = str_replace(array('&gt;', '&lt;'), array('>', '<'), $code);
177
            $code = highlight_string('<?php ' . $code, true);
178
            $code = str_replace('<span style="color: #0000BB">&lt;?php&nbsp;<br />', '<span style="color: #0000BB">', $code);
179
180
            $out = $out . substr($content, $last, $start + strlen($startTag) - $last) . $code . $endTag;
181
            $last = $end + strlen($endTag);
182
        }
183
        $out .= substr($content, $last, strlen($content));
184
185
        return $out;
186
    }
187
}
188
189
}
190
191
namespace {
192
193
use PhpXmlRpc\Builder;
194
195
function run_default($task=null, $args=array(), $cliOpts=array())
0 ignored issues
show
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

195
function run_default($task=null, /** @scrutinizer ignore-unused */ $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $cliOpts is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

195
function run_default($task=null, $args=array(), /** @scrutinizer ignore-unused */ $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $task is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

195
function run_default(/** @scrutinizer ignore-unused */ $task=null, $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
196
{
197
    echo "Syntax: pake {\$pake-options} \$task \$lib-version [\$git-tag] {\$task-options}\n";
198
    echo "\n";
199
    echo "  Run 'pake help' to list all pake options\n";
200
    echo "  Run 'pake -T' to list available tasks\n";
201
    echo "  Run 'pake -P' to list all available tasks (including hidden ones) and their dependencies\n";
202
    echo "\n";
203
    echo "  Task options:\n";
204
    echo "      --repo=REPO      URL of the source repository to clone. Defaults to the github repo.\n";
205
    echo "      --branch=BRANCH  The git branch to build from. Defaults to master\n";
206
    echo "      --workspace=DIR   The dir where to check out source code. Defaults to build/workspace\n";
207
    echo "      --asciidoctor=ASCIIDOCTOR Location of the asciidoctor command-line tool\n";
208
    echo "      --fop=FOP        Location of the apache fop command-line tool\n";
209
    echo "      --php=PHP        Location of the php command-line interpreter\n";
210
    echo "      --zip=ZIP        Location of the zip tool\n";
211
}
212
213
function run_getopts($task=null, $args=array(), $cliOpts=array())
0 ignored issues
show
The parameter $task is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

213
function run_getopts(/** @scrutinizer ignore-unused */ $task=null, $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
214
{
215
    Builder::getOpts($args, $cliOpts);
216
}
217
218
/**
219
 * Downloads source code in the build workspace directory, optionally checking out the given branch/tag
220
 * @todo allow using current installation / dir as source, bypassing git clone in workspace - at least for doc generation
221
 */
222
function run_init($task=null, $args=array(), $cliOpts=array())
0 ignored issues
show
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

222
function run_init($task=null, /** @scrutinizer ignore-unused */ $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $cliOpts is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

222
function run_init($task=null, $args=array(), /** @scrutinizer ignore-unused */ $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $task is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

222
function run_init(/** @scrutinizer ignore-unused */ $task=null, $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
223
{
224
    // download the current version into the workspace
225
    $targetDir = Builder::workspaceDir();
226
227
    // check if workspace exists and is not already set to the correct repo
228
    if (is_dir($targetDir) && pakeGit::isRepository($targetDir)) {
0 ignored issues
show
The type pakeGit was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
229
        $repo = new pakeGit($targetDir);
230
        $remotes = $repo->remotes();
231
        if (trim($remotes['origin']['fetch']) != Builder::option('repo')) {
232
            throw new Exception("Directory '$targetDir' exists and is not linked to correct git repo");
233
        }
234
235
        /// @todo we should just fetch if we are checking out a tag, but pull if we are checking out a branch...
236
        $repo->pull();
237
    } else {
238
        pake_mkdirs(dirname($targetDir));
0 ignored issues
show
The function pake_mkdirs was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

238
        /** @scrutinizer ignore-call */ 
239
        pake_mkdirs(dirname($targetDir));
Loading history...
239
        $repo = pakeGit::clone_repository(Builder::option('repo'), Builder::workspaceDir());
240
    }
241
242
    $repo->checkout(Builder::option('branch'));
243
}
244
245
/**
246
 * Runs all the build steps.
247
 *
248
 * (does nothing by itself, as all the steps are managed via task dependencies)
249
 */
250
function run_build($task=null, $args=array(), $cliOpts=array())
0 ignored issues
show
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

250
function run_build($task=null, /** @scrutinizer ignore-unused */ $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $cliOpts is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

250
function run_build($task=null, $args=array(), /** @scrutinizer ignore-unused */ $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $task is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

250
function run_build(/** @scrutinizer ignore-unused */ $task=null, $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
251
{
252
}
253
254
function run_clean_doc()
255
{
256
    pake_remove_dir(Builder::workspaceDir().'/doc/api');
0 ignored issues
show
The function pake_remove_dir was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

256
    /** @scrutinizer ignore-call */ 
257
    pake_remove_dir(Builder::workspaceDir().'/doc/api');
Loading history...
257
    $finder = pakeFinder::type('file')->name('*.html');
0 ignored issues
show
The type pakeFinder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
258
    pake_remove($finder, Builder::workspaceDir().'/doc/manual');
0 ignored issues
show
The function pake_remove was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

258
    /** @scrutinizer ignore-call */ 
259
    pake_remove($finder, Builder::workspaceDir().'/doc/manual');
Loading history...
259
    $finder = pakeFinder::type('file')->name('*.xml');
260
    pake_remove($finder, Builder::workspaceDir().'/doc/manual');
261
}
262
263
/**
264
 * Generates documentation in all formats
265
 */
266
function run_doc($task=null, $args=array(), $cliOpts=array())
0 ignored issues
show
The parameter $cliOpts is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

266
function run_doc($task=null, $args=array(), /** @scrutinizer ignore-unused */ $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

266
function run_doc($task=null, /** @scrutinizer ignore-unused */ $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $task is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

266
function run_doc(/** @scrutinizer ignore-unused */ $task=null, $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
267
{
268
    // in
269
    $srcDir = Builder::workspaceDir();
270
    // out
271
    $docDir = Builder::workspaceDir().'/doc';
272
273
    // API docs
274
275
    // from phpdoc comments using phpdocumentor
276
    $cmd = Builder::tool('php');
277
    pake_sh("$cmd " . Builder::toolsDir(). "/vendor/bin/phpdoc run --cache-folder ".Builder::buildDir()."/.phpdoc -d ".$srcDir.'/src'." -t ".$docDir.'/api --title PHP-XMLRPC');
0 ignored issues
show
The function pake_sh was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

277
    /** @scrutinizer ignore-call */ 
278
    pake_sh("$cmd " . Builder::toolsDir(). "/vendor/bin/phpdoc run --cache-folder ".Builder::buildDir()."/.phpdoc -d ".$srcDir.'/src'." -t ".$docDir.'/api --title PHP-XMLRPC');
Loading history...
278
279
    // from phpdoc comments using Sami
280
    // deprecated on 2021/12, as Sami is abandonware
281
    /*$samiConfig = <<<EOT
282
<?php
283
    \$iterator = Symfony\Component\Finder\Finder::create()
284
      ->files()
285
      ->exclude('debugger')
286
      ->exclude('demo')
287
      ->exclude('doc')
288
      ->exclude('tests')
289
      ->in('./build/workspace');
290
    return new Sami\Sami(\$iterator, array(
291
        'title' => 'PHP-XMLRPC',
292
        'build_dir' => 'build/workspace/doc/api',
293
        'cache_dir' => 'build/cache',
294
    ));
295
EOT;
296
    file_put_contents('build/sami_config.php', $samiConfig);
297
    $cmd = Builder::tool('php');
298
    pake_sh("$cmd " . Builder::toolsDir(). "/vendor/bin/sami.php update -vvv build/sami_config.php");*/
299
300
    // User Manual
301
302
    // html (single file) from asciidoc
303
    $cmd = Builder::tool('asciidoctor');
304
    pake_sh("$cmd -d book -o $docDir/manual/phpxmlrpc_manual.html $srcDir/doc/manual/phpxmlrpc_manual.adoc");
305
306
    // then docbook from asciidoc
307
    /// @todo create phpxmlrpc_manual.xml with the good version number
308
    /// @todo create phpxmlrpc_manual.xml with the date set to the one of last commit (or today?)
309
    pake_sh("$cmd -d book -b docbook -o $docDir/manual/phpxmlrpc_manual.xml $srcDir/doc/manual/phpxmlrpc_manual.adoc");
310
311
    # Other tools for docbook...
312
    #
313
    # jade cmd yet to be rebuilt, starting from xml file and putting output in ./out dir, e.g.
314
    #	jade -t xml -d custom.dsl xmlrpc_php.xml
315
    #
316
    # convertdoc command for xmlmind xxe editor
317
    #	convertdoc docb.toHTML xmlrpc_php.xml -u out
318
    #
319
    # saxon + xerces xml parser + saxon extensions + xslthl: adds a little syntax highlighting
320
    # (bold and italics only, no color) for php source examples...
321
    #	java \
322
    #	-classpath c:\programmi\saxon\saxon.jar\;c:\programmi\saxon\xslthl.jar\;c:\programmi\xerces\xercesImpl.jar\;C:\htdocs\xmlrpc_cvs\docbook-xsl\extensions\saxon65.jar \
323
    #	-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl \
324
    #	-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl \
325
    #	-Dxslthl.config=file:///c:/htdocs/xmlrpc_cvs/docbook-xsl/highlighting/xslthl-config.xml \
326
    #	com.icl.saxon.StyleSheet -o xmlrpc_php.fo.xml xmlrpc_php.xml custom.fo.xsl use.extensions=1
327
328
    // HTML (multiple files) from docbook - discontinued, as we use the nicer-looking html gotten from asciidoc
329
    /*Builder::applyXslt($docDir.'/manual/phpxmlrpc_manual.xml', $docDir.'/build/custom.xsl', $docDir.'/manual');
330
    // post process html files to highlight php code samples
331
    foreach(pakeFinder::type('file')->name('*.html')->in($docDir.'/manual') as $file)
332
    {
333
        file_put_contents($file, Builder::highlightPhpInHtml(file_get_contents($file)));
334
    }*/
335
336
    // PDF file from docbook
337
338
    // convert to fo and then to pdf using apache fop
339
    Builder::applyXslt($docDir.'/manual/phpxmlrpc_manual.xml', $docDir.'/build/custom.fo.xsl', $docDir.'/manual/phpxmlrpc_manual.fo.xml');
340
    $cmd = Builder::tool('fop');
341
    pake_sh("$cmd $docDir/manual/phpxmlrpc_manual.fo.xml $docDir/manual/phpxmlrpc_manual.pdf");
342
343
    // cleanup
344
    unlink($docDir.'/manual/phpxmlrpc_manual.xml');
345
    unlink($docDir.'/manual/phpxmlrpc_manual.fo.xml');
346
}
347
348
function run_clean_dist()
349
{
350
    pake_remove_dir(Builder::distDir());
0 ignored issues
show
The function pake_remove_dir was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

350
    /** @scrutinizer ignore-call */ 
351
    pake_remove_dir(Builder::distDir());
Loading history...
351
    $finder = pakeFinder::type('file')->name(Builder::distFiles());
352
    pake_remove($finder, Builder::buildDir());
0 ignored issues
show
The function pake_remove was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

352
    /** @scrutinizer ignore-call */ 
353
    pake_remove($finder, Builder::buildDir());
Loading history...
353
}
354
355
/**
356
 * Creates the tarballs for a release
357
 */
358
function run_dist($task=null, $args=array(), $cliOpts=array())
0 ignored issues
show
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

358
function run_dist($task=null, /** @scrutinizer ignore-unused */ $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $cliOpts is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

358
function run_dist($task=null, $args=array(), /** @scrutinizer ignore-unused */ $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $task is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

358
function run_dist(/** @scrutinizer ignore-unused */ $task=null, $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
359
{
360
    // copy workspace dir into dist dir, without git
361
    pake_mkdirs(Builder::distDir());
0 ignored issues
show
The function pake_mkdirs was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

361
    /** @scrutinizer ignore-call */ 
362
    pake_mkdirs(Builder::distDir());
Loading history...
362
    $finder = pakeFinder::type('any')->ignore_version_control();
363
    /// @todo make sure we don't recurse - avoid 'build' dir
364
    pake_mirror($finder, realpath(Builder::workspaceDir()), realpath(Builder::distDir()));
0 ignored issues
show
The function pake_mirror was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

364
    /** @scrutinizer ignore-call */ 
365
    pake_mirror($finder, realpath(Builder::workspaceDir()), realpath(Builder::distDir()));
Loading history...
365
366
    // @todo remove unwanted files from dist dir - files and dirs from .gitattributes
367
368
    // also: do we still need to run dos2unix?
369
370
    // create tarballs
371
    $cwd = getcwd();
372
    chdir(dirname(Builder::distDir()));
373
    foreach(Builder::distFiles() as $distFile) {
374
        // php can not really create good zip files via phar: they are not compressed!
375
        if (substr($distFile, -4) == '.zip') {
376
            $cmd = Builder::tool('zip');
377
            $extra = '-9 -r';
378
            pake_sh("$cmd $distFile $extra ".basename(Builder::distDir()));
0 ignored issues
show
The function pake_sh was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

378
            /** @scrutinizer ignore-call */ 
379
            pake_sh("$cmd $distFile $extra ".basename(Builder::distDir()));
Loading history...
379
        }
380
        else {
381
            $finder = pakeFinder::type('any')->pattern(basename(Builder::distDir()).'/**');
382
            // see https://bugs.php.net/bug.php?id=58852
383
            $pharFile = str_replace(Builder::libVersion(), '_LIBVERSION_', $distFile);
384
            pakeArchive::createArchive($finder, '.', $pharFile);
0 ignored issues
show
The type pakeArchive was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
385
            rename($pharFile, $distFile);
386
        }
387
    }
388
    chdir($cwd);
389
}
390
391
function run_clean_workspace($task=null, $args=array(), $cliOpts=array())
0 ignored issues
show
The parameter $task is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

391
function run_clean_workspace(/** @scrutinizer ignore-unused */ $task=null, $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $cliOpts is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

391
function run_clean_workspace($task=null, $args=array(), /** @scrutinizer ignore-unused */ $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

391
function run_clean_workspace($task=null, /** @scrutinizer ignore-unused */ $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
392
{
393
    if (realpath(__DIR__) === realpath(Builder::workspaceDir())) {
394
        throw new \Exception("Can not remove workspace dir, as it is where pakefile is located!");
395
    }
396
    pake_remove_dir(Builder::workspaceDir());
0 ignored issues
show
The function pake_remove_dir was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

396
    /** @scrutinizer ignore-call */ 
397
    pake_remove_dir(Builder::workspaceDir());
Loading history...
397
}
398
399
/**
400
 * Cleans up the whole build directory
401
 * @todo 'make clean' usually just removes the results of the build, distclean removes all but sources
402
 */
403
function run_clean($task=null, $args=array(), $cliOpts=array())
0 ignored issues
show
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

403
function run_clean($task=null, /** @scrutinizer ignore-unused */ $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $task is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

403
function run_clean(/** @scrutinizer ignore-unused */ $task=null, $args=array(), $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $cliOpts is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

403
function run_clean($task=null, $args=array(), /** @scrutinizer ignore-unused */ $cliOpts=array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
404
{
405
    pake_remove_dir(Builder::buildDir());
0 ignored issues
show
The function pake_remove_dir was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

405
    /** @scrutinizer ignore-call */ 
406
    pake_remove_dir(Builder::buildDir());
Loading history...
406
}
407
408
// helper task: display help text
409
pake_task( 'default' );
0 ignored issues
show
The function pake_task was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

409
/** @scrutinizer ignore-call */ 
410
pake_task( 'default' );
Loading history...
410
// internal task: parse cli options
411
pake_task('getopts');
412
pake_task('init', 'getopts');
413
pake_task('doc', 'getopts', 'init', 'clean-doc');
414
pake_task('build', 'getopts', 'init', 'doc');
415
pake_task('dist', 'getopts', 'init', 'build', 'clean-dist');
416
pake_task('clean-doc', 'getopts');
417
pake_task('clean-dist', 'getopts');
418
pake_task('clean-workspace', 'getopts');
419
pake_task('clean', 'getopts');
420
421
}
422