Completed
Push — master ( 262946...6e3469 )
by CodexShaper
03:22
created

ComposerScripts::postAutoloadDump()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 53

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
nc 6
nop 1
dl 0
loc 53
ccs 0
cts 26
cp 0
crap 20
rs 9.0254
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace CodexShaper\WP;
4
5
use Composer\Script\Event;
6
7
class ComposerScripts
8
{
9
    /**
10
     * Handle the post-install Composer event.
11
     *
12
     * @param  \Composer\Script\Event  $event
13
     * @return void
14
     */
15
    public static function postInstall(Event $event)
16
    {
17
        require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php';
18
    }
19
20
    /**
21
     * Handle the post-update Composer event.
22
     *
23
     * @param  \Composer\Script\Event  $event
24
     * @return void
25
     */
26
    public static function postUpdate(Event $event)
27
    {
28
        require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php';
29
    }
30
31
    /**
32
     * Handle the post-autoload-dump Composer event.
33
     *
34
     * @param  \Composer\Script\Event  $event
35
     * @return void
36
     */
37
    public static function postAutoloadDump(Event $event)
38
    {
39
        require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php';
40
41
        $dir = $event->getComposer()->getConfig()->get('vendor-dir').'/../';
0 ignored issues
show
Unused Code introduced by
$dir is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
42
        $root = dirname($event->getComposer()->getConfig()->get('vendor-dir'));
43
44
        $vendor_name = strtolower(basename($root));
45
        $partials = explode('-', $vendor_name);
46
        $camel_case_partials = [];
47
        foreach ($partials as $partial) {
48
           $camel_case_partials[] = ucfirst(strtolower($partial));
49
        }
50
        $camel_case = implode('_', $camel_case_partials);
51
        $snake_case = implode('_', $partials);
52
53
        $files = [
54
            '/wpb.php',
55
            '/bootstrap/app.php',
56
            '/includes/class-wpb-activator.php',
57
            '/includes/class-wpb-deactivator.php',
58
            '/includes/class-wpb-i18n.php',
59
            '/includes/class-wpb-loader.php',
60
            '/includes/class-wpb.php',
61
            '/admin/class-wpb-admin.php',
62
            '/admin/partials/wpb-admin-display.php',
63
            '/admin/css/wpb-admin.css',
64
            '/admin/js/wpb-admin.js',
65
            '/public/class-wpb-public.php',
66
            '/public/partials/wpb-public-display.php',
67
            '/public/css/wpb-public.css',
68
            '/public/js/wpb-public.js',
69
        ];
70
71
        foreach ($files as $file) {
72
            $file = $root.$file;
73
            if(file_exists($file)) {
74
                $contents = file_get_contents($file);
75
                $contents = str_replace('wpb_', $snake_case.'_', $contents);
76
                $contents = str_replace('wpb', $vendor_name, $contents);
77
                $contents = str_replace('WPB', $camel_case, $contents);
78
                file_put_contents(
79
                    $file,
80
                    $contents
81
                );
82
83
                $dir = dirname($file);
84
                $fileName = basename($file);
85
                $newFileName = str_replace('wpb', $vendor_name, $fileName);
86
                rename($file, $dir.'/'.$newFileName.'.php');
87
            }
88
        }
89
    }
90
}
91