Completed
Push — master ( 076ad5...3005ec )
by AJ
14:22
created

ShopifyInstallShell   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 5
dl 0
loc 103
ccs 0
cts 68
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D main() 0 99 18
1
<?php
2
/**
3
 * CakePHPify : CakePHP Plugin for Shopify API Authentication
4
 * Copyright (c) Multidimension.al (http://multidimension.al)
5
 * Github : https://github.com/multidimension-al/cakephpify
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE file
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright     (c) Multidimension.al (http://multidimension.al)
12
 * @link          https://github.com/multidimension-al/cakephpify CakePHPify Github
13
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
14
 */
15
16
17
namespace Multidimensional\Cakephpify\Shell;
18
19
use Cake\Core\Configure;
20
use Cake\Console\Shell;
21
use Cake\Console\Helper;
22
use Migrations\Migrations;
23
24
class ShopifyInstallShell extends Shell
25
{
26
27
    public function main()
28
    {
29
30
        $this->clear();
31
32
        $this->_io->styles('error', ['text' => 'red']);
33
        $this->helper('Multidimensional/Cakephpify.Header')->output();
0 ignored issues
show
Bug introduced by
The call to output() misses a required argument $args.

This check looks for function calls that miss required arguments.

Loading history...
34
35
        $first_run = ((Configure::check('Multidimensional/Cakephpify')) ? false : true);
0 ignored issues
show
Coding Style introduced by
$first_run does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
36
            
37
        //Activate Plugin           
38
        if ((($first_run) ? (strtolower($this->in('Install Shopify Plugin?', ['y','n'])) == 'y') : (strtolower($this->in('Update Configuration?', ['y','n'])) == 'y'))) {
0 ignored issues
show
Coding Style introduced by
$first_run does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
39
            
40
41
            $this->out();
42
            $this->out('Please enter your API credentials from your Shopify App page.', 2);
43
            $apiKey = $this->in('API Key:');
0 ignored issues
show
Unused Code introduced by
$apiKey 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...
44
            $this->out();
45
46
            Configure::write('Multidimensional/Cakephpify.' . $api_key . '.shared_secret', $this->in('Shared Secret:'));
0 ignored issues
show
Coding Style introduced by
$api_key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The variable $api_key does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
47
48
            $this->out();
49
50
            $scopeArray = ['read_content', 'write_content', 'read_themes', 'write_themes', 'read_products', 'write_products', 'read_customers', 'write_customers', 'read_orders', 'write_orders', 'read_script_tags', 'write_script_tags', 'read_fulfillments', 'write_fulfillments', 'read_shipping', 'write_shipping', 'read_analytics', 'read_users', 'write_users'];
51
52
            $this->out('Enter your application\'s scope here.', 2);
53
            $this->out('Valid scope options:', 2);
54
            $this->helper('Multidimensional/Cakephpify.Table')->output($scopeArray);
55
            $this->out('');
56
            $this->out('Separate your desired scope options with a comma.');
57
58
            do {
59
                $this->out('');
60
                $scope = $this->in('Scope:');
61
62
                $scope = explode(",", $scope);
63
64
                if (!is_array($scope)) {
65
                    $scope = [$scope];
66
                }
67
                $scope = array_map('trim', $scope);
68
                $scope = array_map('strtolower', $scope);
69
                array_walk($scope, function (&$value) {
70
                    $value = str_replace(" ", "_", $value);
71
                });
72
73
                if ((count($scope)) && (strlen(trim(implode("", $scope))) > 0) && (count(array_diff($scope, $scopeArray)) > 0)) {
74
                    $this->out('');
75
                    $this->_io->out('<error>Invalid Scope. Try again, or leave blank to continue.</error>');
76
                }
77
78
            } while((count($scope)) && (strlen(trim(implode("", $scope))) > 0) && (count(array_diff($scope, $scope_array)) > 0));
0 ignored issues
show
Coding Style introduced by
$scope_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The variable $scope_array does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
79
            
80
            Configure::write('Multidimensional/Cakephpify.' . $api_key . '.scope',implode(',', $scope));
0 ignored issues
show
Coding Style introduced by
$api_key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
81
            
82
            $this->out('');
83
            $isPrivateApp = strtolower($this->in('Is this a private app?', ['y', 'n']));
84
85
            if ($isPrivateApp == 'y') {
86
                $isPrivateApp = 'true';
0 ignored issues
show
Unused Code introduced by
$isPrivateApp 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...
87
            } else {
88
                $isPrivateApp = 'false';
0 ignored issues
show
Unused Code introduced by
$isPrivateApp 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...
89
            }
90
91
            
92
            Configure::write('Multidimensional/Cakephpify.' . $api_key . '.is_private_app',$is_private_app);
0 ignored issues
show
Coding Style introduced by
$api_key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The variable $is_private_app does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
93
            
94
            if ($is_private_app == 'true') {
0 ignored issues
show
Coding Style introduced by
$is_private_app does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
95
                Configure::write('Multidimensional/Cakephpify.' . $api_key . '.private_app_password',$this->in('Private App Password:'));
0 ignored issues
show
Coding Style introduced by
$api_key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
96
            } else {
97
                Configure::write('Multidimensional/Cakephpify.' . $api_key . '.private_app_password', NULL);
0 ignored issues
show
Coding Style introduced by
$api_key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
98
            }
99
            
100
            Configure::dump('shopify', 'default', ['Multidimensional/Cakephpify']);
101
            
102
        }
103
104
        $this->out('');
105
106
        if (($firstRun) || (strtolower($this->in('Update Database?', ['y', 'n'])) == 'y')) {
0 ignored issues
show
Bug introduced by
The variable $firstRun does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
107
            $this->out('');
108
109
            $migrations = new Migrations(['plugin' => 'Multidimensional/Cakephpify']);
110
111
            $status = $migrations->status();
112
113
            if ((is_array($status)) && (count($status))) {
114
                $this->out('Updating Databases', 2);
115
116
                if ($migrations->migrate()) {
117
                    $this->out('Success!', 2);
118
                } else {
119
                    $this->_io->out('<error>Update Failed!</error>', 2);
120
                }
121
            } else {
122
                $this->out('Shopify Database Files Not Found', 2);
123
            }
124
        }
125
    }
126
}
127