Generic::createDefinition()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
c 0
b 0
f 0
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 samsonframework\orm\generator;
8
9
use samsonphp\generator\Generator;
10
11
/**
12
 * Generic object-oriented programming class generator.
13
 *
14
 * @package samsonframework\ormgenerator
15
 */
16
abstract class Generic
17
{
18
    /** Generated classes namespace prefix */
19
    const GENERATED_NAMESPACE = '\samsonframework\orm\generated\\';
20
21
    /** @var string Generated class name */
22
    public $className;
23
24
    /** @var string Generated parent class */
25
    protected $parentClass;
26
27
    /** @var Generator Code generation instance */
28
    protected $generator;
29
30
    /** @var \samsonframework\ormgenerator\metadata\GenericMetadata Entity query Generic */
31
    protected $metadata;
32
33
    /**
34
     * OOP constructor.
35
     *
36
     * @param Generator                                               $generator Code generation instance
37
     * @param \samsonframework\orm\generator\metadata\GenericMetadata $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...
38
     */
39
    public function __construct(Generator $generator, $metadata)
40
    {
41
        $this->metadata = $metadata;
42
        $this->generator = $generator;
43
        $this->className = $metadata->entity;
44
    }
45
46
    /**
47
     * Generic class generation.
48
     *
49
     * @param Generic|metadata\GenericMetadata $metadata Entity metadata
50
     *
51
     * @return string Generated PHP class code
52
     */
53
    public function generate(Generic $metadata = null)
54
    {
55
        $metadata = null === $metadata ? $this->metadata : $metadata;
56
57
        $this->createUses($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 55 can also be of type object<samsonframework\orm\generator\Generic>; however, samsonframework\orm\gene...r\Generic::createUses() does only seem to accept object<samsonframework\o...tadata\GenericMetadata>, 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...
58
        $this->createDefinition($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 55 can also be of type object<samsonframework\orm\generator\Generic>; however, samsonframework\orm\gene...ric::createDefinition() does only seem to accept object<samsonframework\o...tadata\GenericMetadata>, 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...
59
        $this->createConstants($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 55 can also be of type object<samsonframework\orm\generator\Generic>; however, samsonframework\orm\gene...eric::createConstants() does only seem to accept object<samsonframework\o...tadata\GenericMetadata>, 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...
60
        $this->createStaticFields($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 55 can also be of type object<samsonframework\orm\generator\Generic>; however, samsonframework\orm\gene...c::createStaticFields() does only seem to accept object<samsonframework\o...tadata\GenericMetadata>, 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...
61
        $this->createStaticMethods($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 55 can also be of type object<samsonframework\orm\generator\Generic>; however, samsonframework\orm\gene...::createStaticMethods() does only seem to accept object<samsonframework\o...tadata\GenericMetadata>, 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...
62
        $this->createFields($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 55 can also be of type object<samsonframework\orm\generator\Generic>; however, samsonframework\orm\gene...Generic::createFields() does only seem to accept object<samsonframework\o...tadata\GenericMetadata>, 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...
63
        $this->createMethods($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 55 can also be of type object<samsonframework\orm\generator\Generic>; however, samsonframework\orm\gene...eneric::createMethods() does only seem to accept object<samsonframework\o...tadata\GenericMetadata>, 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...
64
        $this->createConstructor($metadata);
0 ignored issues
show
Bug introduced by
It seems like $metadata defined by null === $metadata ? $this->metadata : $metadata on line 55 can also be of type object<samsonframework\orm\generator\Generic>; however, samsonframework\orm\gene...ic::createConstructor() does only seem to accept object<samsonframework\o...tadata\GenericMetadata>, 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...
65
66
        return $this->generator->endClass()->flush();
67
    }
68
69
    /**
70
     * Class uses generation part.
71
     *
72
     * @param \samsonframework\orm\generator\metadata\GenericMetadata $metadata Entity metadata
73
     */
74
    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...
75
    {
76
77
    }
78
79
    /**
80
     * Class definition generation part.
81
     *
82
     * @param \samsonframework\orm\generator\metadata\GenericMetadata $metadata Entity metadata
83
     */
84
    abstract protected function createDefinition($metadata);
85
86
    /**
87
     * Class constants generation part.
88
     *
89
     * @param \samsonframework\orm\generator\metadata\GenericMetadata $metadata Entity metadata
90
     */
91
    protected function createConstants($metadata)
92
    {
93
94
    }
95
96
    /**
97
     * Class static fields generation part.
98
     *
99
     * @param \samsonframework\orm\generator\metadata\GenericMetadata $metadata Entity metadata
100
     */
101
    protected function createStaticFields($metadata)
102
    {
103
104
    }
105
106
    /**
107
     * Class static methods generation part.
108
     *
109
     * @param \samsonframework\orm\generator\metadata\GenericMetadata $metadata Entity metadata
110
     */
111
    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...
112
    {
113
114
    }
115
116
    /**
117
     * Class fields generation part.
118
     *
119
     * @param \samsonframework\orm\generator\metadata\GenericMetadata $metadata Entity metadata
120
     */
121
    protected function createFields($metadata)
122
    {
123
124
    }
125
126
    /**
127
     * Class methods generation part.
128
     *
129
     * @param \samsonframework\orm\generator\metadata\GenericMetadata $metadata Entity metadata
130
     */
131
    protected function createMethods($metadata)
132
    {
133
134
    }
135
136
    /**
137
     * Class constructor generation part.
138
     *
139
     * @param \samsonframework\orm\generator\metadata\GenericMetadata $metadata Entity metadata
140
     */
141
    protected function createConstructor($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...
142
    {
143
144
    }
145
}
146
//[PHPCOMPRESSOR(remove,end)]
147