Completed
Pull Request — master (#66)
by
unknown
01:43
created

ResourcesCommand::getDependencies()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 8.0355
c 0
b 0
f 0
cc 8
nc 4
nop 2
1
<?php namespace Wn\Generators\Commands;
2
3
use InvalidArgumentException;
4
use Symfony\Component\Yaml\Yaml;
5
6
7
class ResourcesCommand extends BaseCommand {
8
9
    protected $signature = 'wn:resources
10
        {files* : Paths to the files containing resources declarations}
11
        {--path= : where to store the model files.}
12
        {--routes= : where to store the routes.}
13
        {--no-routes : do not add routes.}
14
        {--controllers= : where to store the controllers.}
15
        {--no-controllers : do not generate controllers.}
16
        {--no-migration : do not migrate.}
17
        {--check-only : only check supplied files for valide relationships.}
18
        {--skip-check : skip validity check before processing.}
19
        {--force= : override the existing files}
20
        {--force-redefine : Force model redefinition.}
21
        {--laravel= : Use Laravel style route definitions}
22
    ';
23
24
    protected $description = 'Generates multiple resources from a couple of files';
25
26
    protected $pivotTables = [];
27
    protected $morphTables = [];
28
29
    private $nodes = [];
30
    private $checkedErrors = 0;
31
    private $checkErrors = [];
32
    private $checkInfo = [];
33
34
    public function handle()
35
    {
36
        $files = $this->argument('files');
37
        $this->nodes = [];
38
        foreach ($files as $file) {
0 ignored issues
show
Bug introduced by
The expression $files of type array|string|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
39
        	$this->info("Reading file ".$file);
40
41
        	$content = $this->fs->get($file);
42
        	$content = Yaml::parse($content);
43
44
        	foreach ($content as $model => $i){
45
        		/*
46
        			$i['modelname'] = as originally in YAML defined
47
        			$i['name']      = as originally defined in snake_case
48
        			$i['uniquename']= for key in singular studly_case
49
        		*/
50
        		$i['filename'] = $file;
51
        		$i['modelname'] = $model;
52
        		$model = studly_case(str_singular($model));
53
        		$i['uniquename'] = $model;
54
55
        		if (empty($this->nodes[$model]) || $this->option('force-redefine')) {
56 View Code Duplication
        			if (!empty($this->nodes[$model])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
        				$this->checkError($model . ": forced to redefine (in file " . $this->nodes[$model]['filename'] . ", redefined from file ".$file.")");
58
        			}
59
        			$i = $this->getResourceParams($i);
60
        			$this->nodes[$model] = $i;
61 View Code Duplication
        		} else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
        			$this->checkError($model . ": already defined (in file " . $this->nodes[$model]['filename'] . ", trying to redefine from file ".$file."; Use --force-redefine to force redefinition)");
63
        		}
64
        	}
65
        }
66
67
        $this->line('');
68
        $this->info('Bringing models to order...');
69
70
        $this->nodes = $this->sortDependencies();
71
72
        if (! $this->option('skip-check')) {
73
        	$this->info('Checking Relationships...');
74
        	$keys = array_keys($this->nodes);
75
        	foreach ($this->nodes as $model => $i) {
76
        		$this->checkRelations($i['belongsTo'], 'belongsTo', $i['filename'], $i['uniquename'], $keys);
77
        		// $this->checkRelations($i['hasManyThrough'], 'hasManyThrough', $file, $model);
78
        	}
79
        	$this->checkPivotRelations($this->pivotTables, 'pivot');
80
        	$this->checkPivotRelations($this->morphTables, 'morph');
81
        }
82
83 View Code Duplication
        if ($this->checkedErrors > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
        	$this->line('');
85
        	if ($this->option('check-only')) {
86
        		$this->info('Checking only, we have found ' . $this->checkedErrors . ' errors.');
87
        	}
88
        	$this->printErrors();
89
        }
90
91
        $proceed = (! $this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check');
92 View Code Duplication
        if (! $this->option('check-only') && $this->checkedErrors > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
        	$this->line('');
94
        	$proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?");
95
        }
96
        if ($proceed) {
97
        	$modelIndex = 0;
98
            $migrationIdLength = strlen((string)count($this->nodes));
99
        	foreach ($this->nodes as $i) {
100
        		$migrationName = 'Create' .  ucwords(str_plural($i['name']));
101
        		$migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , $migrationIdLength, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table';
102
103
        		$this->line('');
104
        		$this->info('Building Model ' . $i['uniquename']);
105
106
        		$options = [
107
        			'name' => $i['name'],
108
        			'fields' => $i['fields'],
109
        			'--add' => $i['add'],
110
        			'--has-many' => $i['hasMany'],
111
        			'--has-one' => $i['hasOne'],
112
        			'--belongs-to' => $i['belongsTo'],
113
        			'--belongs-to-many' => $i['belongsToMany'],
114
        			'--has-many-through' => $i['hasManyThrough'],
115
        			'--morph-to' => $i['morphTo'],
116
        			'--morph-many' => $i['morphMany'],
117
        			'--morph-to-many' => $i['morphToMany'],
118
        			'--morphed-by-many' => $i['morphedByMany'],
119
        			'--no-routes' => $this->option('no-routes'),
120
        			'--no-controller' => $this->option('no-controllers'),
121
        			'--force' => $this->option('force'),
122
        			'--migration-file' => $migrationFile,
123
        		];
124
        		if ($this->option('laravel')) {
125
        			$options['--laravel'] = true;
126
        		}
127
        		if ($this->option('routes')) {
128
        			$options['--routes'] = $this->option('routes');
129
        		}
130
        		if ($this->option('controllers')) {
131
        			$options['--controller'] = $this->option('controllers');
132
        		}
133
        		if ($this->option('path')) {
134
        			$options['--path'] = $this->option('path');
135
        		}
136
137
        		$this->call('wn:resource', $options);
138
        		$modelIndex++;
139
        	}
140
141
        	// if (!$this->option('no-migration')) {
142
        	// 	$this->call('migrate'); // actually needed for pivot seeders !
143
        	// }
144
145
        	$this->pivotTables = array_map(
146
        		'unserialize',
147
        		array_unique(array_map('serialize', $this->pivotTables))
148
        	);
149
150
        	$this->line('');
151 View Code Duplication
        	foreach ($this->pivotTables as $tables) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
        		$this->info('Building Pivot-Table ' . $tables[0] . ' - ' . $tables[1]);
153
        		$this->call('wn:pivot-table', [
154
        			'model1' => $tables[0],
155
        			'model2' => $tables[1],
156
        			'--force' => $this->option('force')
157
        		]);
158
159
        		// $this->call('wn:pivot-seeder', [
160
        		//     'model1' => $tables[0],
161
        		//     'model2' => $tables[1],
162
        		//     '--force' => $this->option('force')
163
        		// ]);
164
        	}
165
166
        	$this->morphTables = array_map(
167
        		'unserialize',
168
        		array_unique(array_map('serialize', $this->morphTables))
169
        	);
170
171
        	$this->line('');
172 View Code Duplication
        	foreach ($this->morphTables as $tables) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
173
        		$this->info('Building Morph-Table ' . $tables[0] . ' - ' . $tables[1]);
174
        		$this->call('wn:morph-table', [
175
        			'model' => $tables[0],
176
        			'morphable' => $tables[1],
177
        			'--force' => $this->option('force')
178
        		]);
179
180
        		// $this->call('wn:pivot-seeder', [
181
        		//     'model1' => $tables[0],
182
        		//     'model2' => $tables[1],
183
        		//     '--force' => $this->option('force')
184
        		// ]);
185
        	}
186
187
        	if (!$this->option('no-migration')) {
188
        		$this->call('migrate');
189
        	}
190
        }
191
    }
192
193
    protected function getResourceParams($i)
194
    {
195
        $modelName = $i['modelname'];
196
197
        $i['filename'] = $i['filename'];
198
        $i['name'] = snake_case($modelName);
199
        $i['modelname'] = $i['modelname'];
200
        $i['uniquename'] = $i['uniquename'];
201
202
        foreach(['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany', 'hasManyThrough', 'morphTo', 'morphMany', 'morphToMany', 'morphedByMany'] as $relation){
203
            if(isset($i[$relation])){
204
                $i[$relation] = $this->convertArray($i[$relation], ' ', ',');
205
            } else {
206
                $i[$relation] = false;
207
            }
208
        }
209
210
        if($i['belongsToMany']){
211
            $relations = $this->getArgumentParser('relations')->parse($i['belongsToMany']);
212
            foreach ($relations as $relation){
213
                $table = '';
0 ignored issues
show
Unused Code introduced by
$table 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...
214
215
                if(! $relation['model']){
216
                    $table = snake_case($relation['name']);
217
                } else {
218
                    $names = array_reverse(explode("\\", $relation['model']));
219
                    $table = snake_case($names[0]);
220
                }
221
222
                $tables = [ str_singular($table), $i['name'] ];
223
                sort($tables);
224
                $tables[] = $modelName;
225
                $this->pivotTables[] = $tables;
226
            }
227
        }
228
229
        if($i['morphToMany']){
230
            $relations = $this->getArgumentParser('relations-morphMany')->parse($i['morphToMany']);
231
            foreach ($relations as $relation){
232
                $table = '';
0 ignored issues
show
Unused Code introduced by
$table 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...
233
234
                if(! $relation['through']){
235
                    $names = array_reverse(explode("\\", $relation['model']));
236
                    $morphable = snake_case($names[0]);
237
                    $model = snake_case($relation['name']);
238 View Code Duplication
                } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
239
                    $names = array_reverse(explode("\\", $relation['through']));
240
                    $morphable = snake_case($names[0]);
241
                    $names = array_reverse(explode("\\", $relation['model']));
242
                    $model = snake_case($names[0]);
243
                }
244
245
                $tables = [ str_singular($model), str_singular($morphable), $modelName ];
246
                $this->morphTables[] = $tables;
247
            }
248
        }
249
250
        if($i['morphedByMany']){
251
            $relations = $this->getArgumentParser('relations-morphMany')->parse($i['morphedByMany']);
252
            foreach ($relations as $relation){
253
                $table = '';
0 ignored issues
show
Unused Code introduced by
$table 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...
254
255 View Code Duplication
                if(! $relation['through']){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
256
                    $names = array_reverse(explode("\\", $relation['model']));
257
                    $morphable = snake_case($names[0]);
258
                } else {
259
                    $names = array_reverse(explode("\\", $relation['through']));
260
                    $morphable = snake_case($names[0]);
261
                }
262
263
                $tables = [ str_singular($i['name']), str_singular($morphable), $modelName ];
264
                $this->morphTables[] = $tables;
265
            }
266
        }
267
268
        $fields = [];
269
        foreach($i['fields'] as $name => $value) {
270
            $value['name'] = $name;
271
            $fields[] = $this->serializeField($value);
272
        }
273
        $i['fields'] = implode(' ', $fields);
274
275
        return $i;
276
    }
277
278
    protected function serializeField($field)
279
    {
280
        $name = $field['name'];
281
        $schema = $this->convertArray(str_replace(':', '.', $field['schema']), ' ', ':');
282
        $rules = (isset($field['rules'])) ? $this->convertArray(trim($field['rules']), ' ', '|') : '';
283
        $tags = !empty($field['tags']) ? $this->convertArray($field['tags'], ' ', ',') : '';
284
285
        $string = "{$name};{$schema};{$rules};{$tags}";
286
287
        if(isset($field['factory']) && !empty($field['factory'])){
288
            $string .= ';' . $field['factory'];
289
        }
290
291
        return $string;
292
    }
293
294
    protected function convertArray($list, $old, $new)
295
    {
296
        return implode($new, array_filter(explode($old, $list), function($item){
297
            return !empty($item);
298
        }));
299
    }
300
301
    private function sortDependencies() {
302
        $load_order = array();
303
        $seen       = array();
304
305
        foreach($this->nodes as $key => $item) {
306
            $tmp = $this->getDependencies($key, $seen);
307
308
            // if($tmp[2] === false) {
309
            $load_order = array_merge($load_order, $tmp[0]);
310
            $seen       = $tmp[1];
311
            // }
312
        }
313
314
        return $load_order;
315
    }
316
317
    private function getDependencies($key, $seen = array()) {
318
        if(array_key_exists($key, $seen) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
319
            return array(array(), $seen);
320
        }
321
322
323
        if(!empty($this->nodes[$key])) {
324
            $order = array();
325
            // $failed         = array();
326
327
            if($this->nodes[$key]['belongsTo']) {
328
                $deps = $this->getArgumentParser('relations')->parse($this->nodes[$key]['belongsTo']);
329
                foreach($deps as $dependency) {
330
                    if(! $dependency['model']){
331
	                    $dependency['model'] = $dependency['name'];
332
	                } else if(strpos($dependency['model'], '\\') !== false ){
333
	                    $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1);
334
	                }
335
                    $dependency['model'] = studly_case(str_singular($dependency['model']));
336
                    if ($dependency['model'] != $key) {
337
                        $tmp = $this->getDependencies($dependency['model'], $seen);
338
339
                        $order  = array_merge($order, $tmp[0]);
340
                        $seen   = $tmp[1];
341
                    }
342
343
                    // if($tmp[2] !== false) {
344
                    //     $failed = array_merge($tmp[2], $failed);
345
                    // }
346
                }
347
            }
348
            $seen[$key]  = true;
349
            $order[$key] = $this->nodes[$key];
350
            // $failed     = (count($failed) > 0) ? $failed : false;
351
352
            return array($order, $seen);//, $failed
353
        }
354
355
        return array(array(), $seen);//, array($item)
356
    }
357
358
    protected function checkError($message, $model = "", $file = "") {
359
        $this->checkErrors[] = array("message" => $message, "model" => $model, "file" => $file);
360
        $this->checkedErrors++;
361
    }
362
363
    protected function checkInfo($message, $model = "", $file = "") {
364
        $this->checkInfo[] = array("message" => $message, "model" => $model, "file" => $file);
365
    }
366
367
    protected function printErrors() {
368
        foreach ($this->checkErrors as $error) {
369
            $this->error($error['message']);
370
        }
371
        foreach ($this->checkInfo as $info) {
372
            $this->info($info['message']);
373
        }
374
    }
375
376
    protected function checkRelations($relations, $type, $file, $model, $keys) {
377
        if ($relations) {
378
            $position = array_search($model, $keys);
379
            $relations = $this->getArgumentParser('relations')->parse($relations);
380
            foreach($relations as $relation) {
381
                switch($type) {
382
                    case "belongsTo":
383
                        $rModel = $relation['model']?$relation['model']:$relation['name']; break;
384
                }
385
386
                $search = array_search(studly_case(str_singular($rModel)), $keys);
0 ignored issues
show
Bug introduced by
The variable $rModel does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
387
                if (($search === false || $search > $position) && !class_exists($this->getNamespace() . '\\' . ucwords(camel_case($rModel))) && !class_exists('App\\' . ucwords(camel_case($rModel)))) {
388
                    $this->checkError(studly_case(str_singular($rModel)) . ": undefined (used in " . $type . "-relationship of model " . $model . " in file " . $file . ")");
389
                } else if (class_exists($this->getNamespace() . '\\' . ucwords(camel_case($rModel)))) {
390
                    $this->checkInfo(studly_case(str_singular($rModel)) . ": already defined in Namespace " . $this->getNamespace() . " (used in " . $type . "-relationship of model " . $model . " in file " . $file . ")");
391
                } else if (class_exists('App\\' . ucwords(camel_case($rModel)))) {
392
                    $this->checkInfo(studly_case(str_singular($rModel)) . ": already defined in Namespace App\\ (used in " . $type . "-relationship of model " . $model . " in file " . $file . ")");
393
                }
394
            }
395
        }
396
    }
397
398
    protected function checkPivotRelations($relations, $rType) {
399
        if ($relations) {
400
            foreach($relations as $relation) {
401
                $relation['0'] = studly_case(str_singular($relation['0']));
402
                $relation['1'] = studly_case(str_singular($relation['1']));
403
                $relation['2'] = studly_case(str_singular($relation['2']));
404
405
                if (empty($this->nodes[$relation['0']]) && !class_exists($this->getNamespace() . '\\' . ucwords(camel_case($relation['0']))) && !class_exists('App\\' . ucwords(camel_case($relation['0'])))) {
406
                    $this->checkError($relation['0'] . ": undefined (used in " . $rType . "-based relationship of model " . $relation['2'] . " in file " . $this->nodes[$relation['2']]['filename'] . ")");
407
                } else if (class_exists($this->getNamespace() . '\\' . ucwords(camel_case($relation['0'])))) {
408
                    $this->checkInfo(studly_case(str_singular($relation['0'])) . ": already defined in Namespace " . $this->getNamespace() . " (used in " . $rType . "-based relationship of model " . $relation['2'] . " in file " . $this->nodes[$relation['2']]['filename'] . ")");
409 View Code Duplication
                } else if (class_exists('App\\' . ucwords(camel_case($relation['0'])))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
410
                    $this->checkInfo(studly_case(str_singular($relation['0'])) . ": already defined in Namespace App\\ (used in " . $rType . "-based relationship of model " . $relation['2'] . " in file " . $this->nodes[$relation['2']]['filename'] . ")");
411
                }
412
413
                if ($rType == "pivot" && empty($this->nodes[$relation['1']]) && !class_exists($this->getNamespace() . '\\' . ucwords(camel_case($relation['1']))) && !class_exists('App\\' . ucwords(camel_case($relation['1'])))) {
414
                    $this->checkError($relation['1'] . ": undefined (used in " . $rType . "-based relationship of model " . $relation['2'] . " in file " . $this->nodes[$relation['2']]['filename'] . ")");
415
                } else if ($rType == "pivot" && class_exists($this->getNamespace() . '\\' . ucwords(camel_case($relation['1'])))) {
416
                    $this->checkInfo(studly_case(str_singular($relation['1'])) . ": already defined in Namespace " . $this->getNamespace() . " (used in " . $rType . "-based relationship of model " . $relation['2'] . " in file " . $this->nodes[$relation['2']]['filename'] . ")");
417 View Code Duplication
                } else if ($rType == "pivot" && class_exists('App\\' . ucwords(camel_case($relation['1'])))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
418
                    $this->checkInfo(studly_case(str_singular($relation['1'])) . ": already defined in Namespace App\\ (used in " . $rType . "-based relationship of model " . $relation['2'] . " in file " . $this->nodes[$relation['2']]['filename'] . ")");
419
                }
420
            }
421
        }
422
    }
423
424
}
425