Completed
Push — master ( 55b21a...aec22b )
by Thomas
06:20
created

ClassBuilder::buildSignature()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
ccs 13
cts 13
cp 1
rs 8.7624
cc 5
eloc 12
nc 16
nop 1
crap 5
1
<?php
2
namespace gossi\codegen\generator\builder;
3
4
use gossi\codegen\model\AbstractModel;
5
use gossi\codegen\model\PhpClass;
6
use gossi\codegen\generator\builder\parts\StructBuilderPart;
7
8
class ClassBuilder extends AbstractBuilder {
9
	
10
	use StructBuilderPart;
11
12 11
	public function build(AbstractModel $model) {
13 11
		$this->sort($model);
1 ignored issue
show
Compatibility introduced by
$model of type object<gossi\codegen\model\AbstractModel> is not a sub-type of object<gossi\codegen\model\PhpClass>. It seems like you assume a child class of the class gossi\codegen\model\AbstractModel to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
14
		
15 11
		$this->buildHeader($model);
1 ignored issue
show
Compatibility introduced by
$model of type object<gossi\codegen\model\AbstractModel> is not a sub-type of object<gossi\codegen\model\AbstractPhpStruct>. It seems like you assume a child class of the class gossi\codegen\model\AbstractModel to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
16
		
17
		// signature
18 11
		$this->buildSignature($model);
1 ignored issue
show
Compatibility introduced by
$model of type object<gossi\codegen\model\AbstractModel> is not a sub-type of object<gossi\codegen\model\PhpClass>. It seems like you assume a child class of the class gossi\codegen\model\AbstractModel to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
19
		
20
		// body
21 11
		$this->writer->writeln(" {\n")->indent();
22 11
		$this->buildTraits($model);
1 ignored issue
show
Documentation introduced by
$model is of type object<gossi\codegen\model\AbstractModel>, but the function expects a object<gossi\codegen\model\TraitsInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23 11
		$this->buildConstants($model);
1 ignored issue
show
Documentation introduced by
$model is of type object<gossi\codegen\model\AbstractModel>, but the function expects a object<gossi\codegen\model\ConstantsInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24 11
		$this->buildProperties($model);
1 ignored issue
show
Documentation introduced by
$model is of type object<gossi\codegen\model\AbstractModel>, but the function expects a object<gossi\codegen\model\PropertiesInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25 11
		$this->buildMethods($model);
1 ignored issue
show
Compatibility introduced by
$model of type object<gossi\codegen\model\AbstractModel> is not a sub-type of object<gossi\codegen\model\AbstractPhpStruct>. It seems like you assume a child class of the class gossi\codegen\model\AbstractModel to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
26 11
		$this->writer->outdent()->rtrim()->write('}');
27 11
	}
28
	
29 11
	private function buildSignature(PhpClass $model) {
30 11
		if ($model->isAbstract()) {
31 2
			$this->writer->write('abstract ');
32
		}
33
		
34 11
		if ($model->isFinal()) {
35 1
			$this->writer->write('final ');
36
		}
37
		
38 11
		$this->writer->write('class ');
39 11
		$this->writer->write($model->getName());
40
		
41 11
		if ($parentClassName = $model->getParentClassName()) {
42 1
			$this->writer->write(' extends ' . $parentClassName);
43
		}
44
		
45 11
		if ($model->hasInterfaces()) {
46 1
			$this->writer->write(' implements ');
47 1
			$this->writer->write(implode(', ', $model->getInterfaces()->toArray()));
48
		}
49 11
	}
50
	
51 11
	private function sort(PhpClass $model) {
52 11
		$this->sortUseStatements($model);
53 11
		$this->sortConstants($model);
54 11
		$this->sortProperties($model);
55 11
		$this->sortMethods($model);
56 11
	}
57
58
}
59