Completed
Push — master ( 8619b3...819e89 )
by Thomas
05:42
created

src/AbstractModel.php (1 issue)

Check that successive assignments are formatted to have their operators in a straight line

Coding Style Informational

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace gossi\swagger;
3
4
abstract class AbstractModel {
5
	
6 6
	protected function export() {
7 6
		$cols = func_get_args();
8
		
9
		// add cols
10 6
		if (method_exists($this, 'hasRef') && $this->hasRef()) {
11 5
			$cols = array_merge(['$ref'], $cols);
12 5
		}
13
		
14
		// flatten array
15 6
		$fields = [];
16
		array_walk_recursive($cols, function($a) use (&$fields) { $fields[] = $a; });
17
18 6
		$out = [];
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
19 6
		$refl = new \ReflectionClass(get_class($this));
20
		
21 6
		foreach ($fields as $field) {
22 6
			if ($field == 'tags') {
23 6
				$val = $this->exportTags();
24 6
			} else {
25 6
				$prop = $refl->getProperty($field == '$ref' ? 'ref' : $field);
26 6
				$prop->setAccessible(true);
27 6
				$val = $prop->getValue($this);
28
				
29 6
				if (method_exists($val, 'toArray')) {
30 6
					$val = $val->toArray();
31 6
				}
32
			}
33
			
34 6
			if ($field == 'required' && is_bool($val) || !empty($val)) {
35 6
				$out[$field] = $val;
36 6
			}
37 6
		}
38
		
39 6
		if (method_exists($this, 'getExtensions')) {
40 6
			$out = array_merge($out, $this->getExtensions()->toArray());
41 6
		}
42
		
43 6
		return $out;
44
	}
45
}