ScriptsHelper::postAutoloadDump()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace MallardDuck\DynamicEcho\Composer;
4
5
use Composer\Script\Event;
6
use Illuminate\Foundation\Application;
7
8
class ScriptsHelper
9
{
10
    /**
11
     * Handle the post-install Composer event.
12
     *
13
     * @param Event $event
14
     * @return void
15
     */
16
    public static function postInstall(Event $event)
17
    {
18
        require_once $event->getComposer()->getConfig()->get('vendor-dir') . '/autoload.php';
19
        static::clearCompiled();
20
    }
21
22
    /**
23
     * Handle the post-update Composer event.
24
     *
25
     * @param Event $event
26
     * @return void
27
     */
28
    public static function postUpdate(Event $event)
29
    {
30
        require_once $event->getComposer()->getConfig()->get('vendor-dir') . '/autoload.php';
31
        static::clearCompiled();
32
    }
33
34
    /**
35
     * Handle the post-autoload-dump Composer event.
36
     *
37
     * @param Event  $event
38
     * @return void
39
     */
40
    public static function postAutoloadDump(Event $event)
41
    {
42
        require_once $event->getComposer()->getConfig()->get('vendor-dir') . '/autoload.php';
43
        static::clearCompiled();
44
    }
45
46
    protected static function clearCompiled()
47
    {
48
        $laravel = new Application(getcwd());
49
        // For now just clear the main cache
50
        if (is_file($servicesPath = $laravel->bootstrapPath('cache/dynamic-echo-discovery.php'))) {
51
            @unlink($servicesPath);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

51
            /** @scrutinizer ignore-unhandled */ @unlink($servicesPath);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
52
        }
53
        // TODO: clear route cache for the broadcast channels.
54
    }
55
}
56