Completed
Push — master ( 4f4aae...6745e3 )
by Vitaly
02:58
created

Generic::createFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
//[PHPCOMPRESSOR(remove,start)]
3
/**
4
 * Created by Vitaly Iegorov <[email protected]>.
5
 * on 22.03.16 at 17:50
6
 */
7
namespace samsoncms\api\generator;
8
9
use samsonphp\generator\Generator;
10
11
/**
12
 * Generic object-oriented programming class generator.
13
 *
14
 * @package samsoncms\api\generator
15
 */
16
abstract class Generic
17
{
18
    /** @var Generator Code generation instance */
19
    protected $generator;
20
21
    /** @var \samsoncms\api\generator\metadata\Generic Entity query Generic */
22
    protected $metadata;
23
24
    /**
25
     * OOP constructor.
26
     *
27
     * @param Generator $generator Code generation instance
28
     * @param \samsoncms\api\generator\metadata\Generic  $Generic Entity query metadata
0 ignored issues
show
Bug introduced by
There is no parameter named $Generic. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
29
     */
30
    public function __construct(Generator $generator, $metadata)
31
    {
32
        $this->metadata = $metadata;
33
        $this->generator = $generator;
34
    }
35
36
    /**
37
     * Generic class generation.
38
     *
39
     * @param \samsoncms\api\generator\metadata\Generic $metadata Entity metadata
40
     *
41
     * @return string Generated PHP class code
42
     */
43
    public function generate(Generic $metadata = null)
44
    {
45
        $metadata = null === $metadata ? $this->metadata : $metadata;
46
47
        $this->createUses($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 45 can also be of type object<samsoncms\api\generator\Generic>; however, samsoncms\api\generator\Generic::createUses() does only seem to accept object<samsoncms\api\generator\metadata\Generic>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
48
        $this->createDefinition($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 45 can also be of type object<samsoncms\api\generator\Generic>; however, samsoncms\api\generator\...ric::createDefinition() does only seem to accept object<samsoncms\api\generator\metadata\Generic>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
49
        $this->createConstants($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 45 can also be of type object<samsoncms\api\generator\Generic>; however, samsoncms\api\generator\Generic::createConstants() does only seem to accept object<samsoncms\api\generator\metadata\Generic>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
50
        $this->createStaticFields($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 45 can also be of type object<samsoncms\api\generator\Generic>; however, samsoncms\api\generator\...c::createStaticFields() does only seem to accept object<samsoncms\api\generator\metadata\Generic>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
51
        $this->createStaticMethods($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 45 can also be of type object<samsoncms\api\generator\Generic>; however, samsoncms\api\generator\...::createStaticMethods() does only seem to accept object<samsoncms\api\generator\metadata\Generic>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
52
        $this->createFields($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 45 can also be of type object<samsoncms\api\generator\Generic>; however, samsoncms\api\generator\Generic::createFields() does only seem to accept object<samsoncms\api\generator\metadata\Generic>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
53
        $this->createMethods($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 45 can also be of type object<samsoncms\api\generator\Generic>; however, samsoncms\api\generator\Generic::createMethods() does only seem to accept object<samsoncms\api\generator\metadata\Generic>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
54
        $this->createConstructor($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 45 can also be of type object<samsoncms\api\generator\Generic>; however, samsoncms\api\generator\...ic::createConstructor() does only seem to accept object<samsoncms\api\generator\metadata\Generic>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
55
56
        return $this->generator->endClass()->flush();
57
    }
58
59
    /**
60
     * Class uses generation part.
61
     *
62
     * @param \samsoncms\api\generator\metadata\Generic $metadata Entity metadata
63
     */
64
    protected function createUses($metadata)
0 ignored issues
show
Unused Code introduced by
The parameter $metadata is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66
67
    }
68
69
    /**
70
     * Class definition generation part.
71
     *
72
     * @param \samsoncms\api\generator\metadata\Generic $metadata Entity metadata
73
     */
74
    abstract protected function createDefinition($metadata);
75
76
    /**
77
     * Class constants generation part.
78
     *
79
     * @param \samsoncms\api\generator\metadata\Generic $metadata Entity metadata
80
     */
81
    protected function createConstants($metadata)
82
    {
83
84
    }
85
86
    /**
87
     * Class static fields generation part.
88
     *
89
     * @param \samsoncms\api\generator\metadata\Generic $metadata Entity metadata
90
     */
91
    protected function createStaticFields($metadata)
92
    {
93
94
    }
95
96
    /**
97
     * Class static methods generation part.
98
     *
99
     * @param \samsoncms\api\generator\metadata\Generic $metadata Entity metadata
100
     */
101
    protected function createStaticMethods($metadata)
0 ignored issues
show
Unused Code introduced by
The parameter $metadata is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
102
    {
103
104
    }
105
106
    /**
107
     * Class fields generation part.
108
     *
109
     * @param \samsoncms\api\generator\metadata\Generic $metadata Entity metadata
110
     */
111
    protected function createFields($metadata)
112
    {
113
114
    }
115
116
    /**
117
     * Class methods generation part.
118
     *
119
     * @param \samsoncms\api\generator\metadata\Generic $metadata Entity metadata
120
     */
121
    protected function createMethods($metadata)
122
    {
123
124
    }
125
126
    /**
127
     * Class constructor generation part.
128
     *
129
     * @param \samsoncms\api\generator\metadata\Generic $metadata Entity metadata
130
     */
131
    protected function createConstructor($metadata)
132
    {
133
134
    }
135
}
136
//[PHPCOMPRESSOR(remove,end)]
137