Generator::defVar()   D
last analyzed

Complexity

Conditions 10
Paths 10

Size

Total Lines 31
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 2
Metric Value
c 5
b 1
f 2
dl 0
loc 31
rs 4.8196
cc 10
eloc 23
nc 10
nop 5

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
//[PHPCOMPRESSOR(remove,start)]
3
namespace samsonphp\generator;
4
5
/**
6
 * PHP code generator.
7
 * @deprecated Use other separate generators.
8
 * @author     Vitaly Egorov <[email protected]>
9
 */
10
class Generator
11
{
12
    /** Single quote for string value **/
13
    const QUOTE_SINGLE = "'";
14
15
    /** Double quote for string value **/
16
    const QUOTE_DOUBLE = '"';
17
18
    /** No quote for string heredoc value **/
19
    const QUOTE_NO = '';
20
21
22
    /** @var string Generated code */
23
    public $code = '';
24
25
    /** @var integer Level of code line tabbing for new lines */
26
    public $tabs = 0;
27
28
    /** @var string Current class name */
29
    public $class;
30
31
    /** @var int Current conditions nesting level */
32
    public $ifConditionLevel = 0;
33
34
    /**
35
     * Constructor
36
     *
37
     * @param string $namespace Code namespace
38
     *
39
     * @deprecated Use new generators logic
40
     */
41
    public function __construct($namespace = null)
42
    {
43
        // If namespace is defined - set it
44
        if (isset($namespace)) {
45
            $this->defNamespace($namespace);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::defNamespace() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
46
        }
47
    }
48
49
    /**
50
     * Add namespace declaration.
51
     *
52
     * @param string $name Namespace name
53
     *
54
     * @deprecated Use new generators logic
55
     * @return $this Chaining
56
     */
57
    public function defNamespace($name)
58
    {
59
        if ($name !== '' && $name !== null) {
60
            $this->newLine('namespace ' . $name . ';')->newLine();
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
61
        }
62
63
        return $this;
64
    }
65
    
66
    /**
67
     * Add new line to code.
68
     *
69
     * @param string $text Code to add to new line
70
     * @param integer $tabs Tabs count
71
     * 
72
*@return self
73
     * @deprecated Use new generators logic
74
     */
75
    public function newLine($text = '', $tabs = null)
76
    {
77
        // If no tabs count is specified set default tabs
78
        if (!isset($tabs)) {
79
            $tabs = $this->tabs;
80
        }
81
82
        return $this->tabs($text, $tabs, "\n");
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::tabs() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
83
    }
84
85
    /**
86
     * Add current tabbing level to current line.
87
     *
88
     * @param string  $endText   Text to add after tabs
89
     * @param integer $tabs      Amount of tabs to add
90
     * @param string  $startText Text to add before tabs
91
     *
92
     * @return Generator Chaining
93
     * @deprecated Use new generators logic
94
     */
95
    public function tabs($endText = '', $tabs = null, $startText = '')
96
    {
97
        // Generate tabs array
98
        $tabs = isset($tabs) && $tabs > 0 ? array_fill(0, $tabs, "\t") : array();
99
100
        // Add necessary amount of tabs to line and append text
101
        $this->text($startText . implode('', $tabs) . $endText);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
102
103
        return $this;
104
    }
105
106
    /**
107
     * Add simple text to current code position
108
     *
109
     * @param string $text Text to add
110
     *
111
     * @return self
112
     * @deprecated Use new generators logic
113
     */
114
    public function text($text = '')
115
    {
116
        $this->code .= $text;
117
118
        return $this;
119
    }
120
121
    /**
122
     * Increase current code indentation.
123
     *
124
     * @param int $amount Indentation amount
125
     *
126
     * @deprecated Use new generators logic
127
     *
128
     * @return $this Chaining
129
     */
130
    public function increaseIndentation($amount = 1)
131
    {
132
        $this->tabs += $amount;
133
134
        return $this;
135
    }
136
137
    /**
138
     * Reduce current code indentation.
139
     *
140
     * @param int $amount Indentation amount
141
     *
142
     * @deprecated Use new generators logic
143
     *
144
     * @return $this Chaining
145
     */
146
    public function decreaseIndentation($amount = 1)
147
    {
148
        $this->tabs = $this->tabs > $amount ? $this->tabs - $amount : 0;
149
150
        return $this;
151
    }
152
153
    /**
154
     * Add single line comment to code
155
     *
156
     * @param string $text Comment text
157
     *
158
     * @return self Chaining
159
     * @deprecated Use new generators logic
160
     */
161
    public function comment($text = '')
162
    {
163
        return isset($text{0}) ? $this->newLine("// " . $text) : $this;
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
164
    }
165
166
    /**
167
     * Add one line variable definition comment.
168
     *
169
     * @param string $type Variable typeHint
170
     * @param string $description Variable description
171
     * @param string $name Variable name
172
     * 
173
*@return self Chaining
174
     * @deprecated Use new generators logic
175
     */
176
    public function commentVar($type, $description, $name = '')
177
    {
178
        return $this->multiComment(array(
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::multiComment() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
179
            '@var ' . trim($type) . (isset($name) ? trim($name) . ' ' : ' ') . trim($description)
180
        ));
181
    }
182
183
    /**
184
     * Add multi-line comment. If array with one line is passed
185
     * we create special syntax comment in one line, usually
186
     * used for class variable definition in more compact form.
187
     *
188
     * @param array $lines Array of comments lines
189
     *
190
     * @deprecated Use new generators logic
191
     * @return self Chaining
192
     */
193
    public function multiComment(array $lines = array())
194
    {
195
        // If array is not empty
196
        if (sizeof($lines)) {
197
            $this->newLine("/**");
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
198
199
            // Multi-comment with single line
200
            if (sizeof($lines) === 1) {
201
                $this->text(' ' . $lines[0] . ' */');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
202
            } else { // Iterate comments lines and if comment line is not empty
203
                foreach ($lines as $line) {
204
                    if (isset($line{0})) {
205
                        $this->newLine(" * " . $line);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
206
                    }
207
                }
208
209
                return $this->newLine(" */");
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
210
            }
211
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
212
        }
213
214
        return $this;
215
    }
216
217
    /**
218
     * Add variable definition with array merging.
219
     *
220
     * @param string $name Variable name
221
     * @param array $value Array of key-value items for merging it to other array
222
     * @param string $arrayName Name of array to merge to, if no is specified - $name is used
223
     * 
224
*@return self Chaining
225
     * @deprecated Use new generators logic
226
     */
227
    public function defArrayMerge($name, array $value, $arrayName = null)
228
    {
229
        // If no other array is specified - set it to current
230
        if (!isset($arrayName)) {
231
            $arrayName = $name;
232
        }
233
234
        return $this->defvar($name, $value, ' = array_merge( ' . $arrayName . ', ', '')->text(');');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::defVar() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
235
    }
236
237
    /**
238
     * Add variable definition.
239
     *
240
     * @param string $name Variable name
241
     * @param mixed $value Variable default value
242
     * @param string $after String to insert after variable definition
243
     * @param string $end Closing part of variable definition
244
     * @param string $quote Type of quote
245
     * 
246
*@return Generator Chaining
247
     * @deprecated Use new generators logic
248
     */
249
    public function defVar($name, $value = null, $after = ' = ', $end = ';', $quote = self::QUOTE_SINGLE)
250
    {
251
        // Output variable definition
252
        $this->newLine($name);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
253
254
        // Get variable typeHint
255
        switch (gettype($value)) {
256
            case 'integer':
257
            case 'boolean':
258
            case 'double':
259
                $this->text($after)->text($value)->text($end);
0 ignored issues
show
Documentation introduced by
$value is of type integer|boolean|double, but the function expects a string.

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...
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
260
                break;
261
            case 'string':
262
                if (strpos($value, 'EOT') !== false) {
263
                    $this->text($after)->stringValue($value, 0, self::QUOTE_NO)->text($end);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::stringValue() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
264
                } else {
265
                    $this->text($after)->stringValue($value, 0, $quote)->text($end);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::stringValue() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
266
                }
267
                break;
268
            case 'array':
269
                $this->text($after)->arrayValue($value)->text($end);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::arrayValue() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
270
                break;
271
            case 'NULL':
272
            case 'object':
273
            case 'resource':
274
            default:
275
                $this->text(';');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
276
        }
277
278
        return $this;
279
    }
280
281
    /**
282
     * Add string value definition.
283
     *
284
     * @param string $value String value to add
285
     * @param string $tabs  Tabs count
286
     * @param string $quote Type of quote
287
     *
288
     * @deprecated Use new generators logic
289
     * @return self Chaining
290
     */
291
    public function stringValue($value, $tabs = null, $quote = self::QUOTE_SINGLE)
292
    {
293
        return $this->tabs($quote . $value . $quote, $tabs);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::tabs() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
294
    }
295
296
    /**
297
     * Add array values definition.
298
     *
299
     * @param array $items Array key-value pairs collection
300
     *
301
     * @deprecated Use new generators logic
302
     * @return self Chaining
303
     */
304
    public function arrayValue(array $items = array())
305
    {
306
        if (sizeof($items)) {
307
            $this->text('[');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
308
            $this->tabs++;
309
310
            // Iterate array items
311
            foreach ($items as $key => $value) {
312
                // Start array key definition
313
                $this->newLine()->defineValue($key)->text(' => ')->defineValue($value)->text(',');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::defineValue() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
314
            }
315
316
            $this->tabs--;
317
            $this->newLine(']');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
318
        } else {
319
            $this->text('[]');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
320
        }
321
322
        return $this;
323
    }
324
325
    /**
326
     * Generate correct value.
327
     *
328
     * Metho handles arrays, numerics, strings and constants.
329
     *
330
     * @param mixed $value Value to put in generated code
331
     *
332
     * @deprecated Use new generators logic
333
     * @return $this
334
     */
335
    protected function defineValue($value)
336
    {
337
        // If item value is array - recursion
338
        if (is_array($value)) {
339
            $this->arrayValue($value);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::arrayValue() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
340
        } elseif (is_numeric($value) || is_float($value)) {
341
            $this->text($value);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
342
        } else {
343
            try { // Try to evaluate
344
                eval('$value2 = ' . $value . ';');
345
                $this->text($value);
0 ignored issues
show
Bug introduced by
It seems like $value defined by parameter $value on line 335 can also be of type boolean or null or object; however, samsonphp\generator\Generator::text() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
346
            } catch (\Throwable $e) { // Consider it as a string
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
347
                $this->stringValue($value);
0 ignored issues
show
Bug introduced by
It seems like $value defined by parameter $value on line 335 can also be of type boolean or null or object; however, samsonphp\generator\Generator::stringValue() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::stringValue() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
348
            }
349
        }
350
351
        return $this;
352
    }
353
354
    /**
355
     * Add trait definition.
356
     *
357
     * @param string $name Trait name
358
     *
359
     * @return self Chaining
360
     * @deprecated Use new generators logic
361
     */
362
    public function defTrait($name)
363
    {
364
        // If we define another class, and we were in other class context
365
        if (isset($this->class) && ($name !== $this->class)) {
366
            // Close old class context
367
            $this->endClass();
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::endClass() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
368
        }
369
370
        // Save new class name
371
        $this->class = $name;
372
373
        // Class definition start
374
        $this->newLine('trait ' . $name);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
375
376
        $this->newLine('{');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
377
378
        $this->tabs++;
379
380
        return $this;
381
    }
382
383
    /**
384
     * Close current class context.
385
     *
386
     * @return self Chaining
387
     * @deprecated Use new generators logic
388
     */
389
    public function endClass()
390
    {
391
        $this->tabs > 0 ? $this->tabs-- : null;
392
393
        // Close class definition
394
        return $this->newLine('}')
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
395
            // Add one empty line after class definition
396
            ->newLine('');
397
    }
398
399
    /**
400
     * Add class definition.
401
     *
402
     * @param string $name Class name
403
     * @param string $extends Parent class name
404
     * @param array $implements Interfaces names collection
405
     *
406
     * @return self Chaining
407
     * @deprecated Use new generators logic
408
     */
409
    public function defClass($name, $extends = null, array $implements = array())
410
    {
411
        // If we define another class, and we were in other class context
412
        if (isset($this->class) && ($name !== $this->class)) {
413
            // Close old class context
414
            $this->endClass();
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::endClass() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
415
        }
416
417
        // Save new class name
418
        $this->class = $name;
419
420
        // Class definition start
421
        $this->newLine('class ' . $name);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
422
423
        // Parent class definition
424
        if (isset($extends)) {
425
            $this->text(' extends ' . $extends);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
426
        }
427
428
        // Interfaces
429
        if (sizeof($implements)) {
430
            $this->text(' implements ' . implode(',', $implements));
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::text() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
431
        }
432
433
        $this->newLine('{');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
434
435
        $this->tabs++;
436
437
        return $this;
438
    }
439
440
    /**
441
     * Define if statement condition.
442
     *
443
     * @param string $condition Condition statement
444
     *
445
     * @return self Chaining
446
     * @deprecated Use new generators logic
447
     */
448
    public function defIfCondition($condition)
449
    {
450
        $this->ifConditionLevel++;
451
452
        // Class definition start
453
        $this->newLine('if (' . $condition . ') {');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
454
        $this->tabs++;
455
        return $this;
456
    }
457
458
    /**
459
     * Define elseif statement condition.
460
     *
461
     * @param string $condition Condition statement
462
     *
463
     * @return self Chaining
464
     * @deprecated Use new generators logic
465
     */
466
    public function defElseIfCondition($condition)
467
    {
468
        $this->tabs--;
469
        // Class definition start
470
        $this->newLine('} elseif (' . $condition . ') {');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
471
        $this->tabs++;
472
        return $this;
473
    }
474
475
    /**
476
     * Define else statement.
477
     *
478
     * @return self Chaining
479
     * @deprecated Use new generators logic
480
     */
481
    public function defElseCondition()
482
    {
483
        $this->tabs--;
484
        // Class definition start
485
        $this->newLine('} else {');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
486
        $this->tabs++;
487
        return $this;
488
    }
489
490
    /**
491
     * Close if condition statement.
492
     *
493
     * @return self Chaining
494
     * @deprecated Use new generators logic
495
     */
496
    public function endIfCondition()
497
    {
498
        if ($this->ifConditionLevel--) {
499
            $this->tabs--;
500
501
            // Close class definition
502
            return $this->newLine('}');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
503
        }
504
505
        return $this;
506
    }
507
508
    /**
509
     * Add class constant definition.
510
     *
511
     * @param string $name  Constant name
512
     * @param string $value Variable default value
513
     *
514
     * @return self Chaining
515
     * @deprecated Use new generators logic
516
     */
517
    public function defClassConst($name, $value)
518
    {
519
        return $this->defClassVar(strtoupper($name), 'const', $value);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::defClassVar() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
520
    }
521
522
    /**
523
     * Add class variable definition.
524
     *
525
     * @param string $name Variable name
526
     * @param string $visibility Variable accessibility level
527
     * @param mixed $value Variable default value
528
     *
529
     * @return self Chaining
530
     * @deprecated Use new generators logic
531
     */
532
    public function defClassVar($name, $visibility = 'public', $value = null)
533
    {
534
        if (isset($comment) && isset($comment{0})) {
0 ignored issues
show
Bug introduced by
The variable $comment seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
535
            $this->multiComment(array($comment));
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::multiComment() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
536
        }
537
538
        return $this->defvar($visibility . ' ' . $name, $value)->newLine();
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::defVar() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
539
    }
540
541
    /**
542
     * Write file to disk
543
     * 
544
*@param string       $name   Path to file
545
     * @param string $format Output file format
546
     *
547
     *@deprecated Use new generators logic
548
     */
549
    public function write($name, $format = 'php')
550
    {
551
        $code = $this->flush();
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::flush() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
552
553
        if ($format === 'php') {
554
            $code = '<?php ' . $code;
555
        }
556
557
        file_put_contents($name, $code, 0775);
558
    }
559
560
    /**
561
     * Flush internal data and return it.
562
     *
563
     * @return string Current generated code
564
     * @deprecated Use new generators logic
565
     */
566
    public function flush()
567
    {
568
        // We should use 4 spaces instead of tabs
569
        $code = str_replace("\t", '    ', $this->code);
570
571
        $this->tabs = 0;
572
        $this->code = '';
573
        $this->class = null;
574
575
        return $code;
576
    }
577
578
    /**
579
     * @see self::defClassFunction with public visibility
580
     *
581
     * @return $this
582
     * @deprecated Use new generators logic
583
     */
584
    public function defPublicClassFunction(string $name, array $parameters = [], array $comments = [], $returnType = null)
585
    {
586
        return $this->defClassFunction($name, 'public', $parameters, $comments, $returnType);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::defClassFunction() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
587
    }
588
589
    /**
590
     * Add class function definition.
591
     *
592
     * @param string $name       Class function name
593
     * @param string $visibility Class function visibility
594
     * @param array  $parameters Class function arguments
595
     * @param array  $comments   Class function multi-line comments
596
     * @param null   $returnType Class function return type PHP7
597
     *
598
     * @return $this
599
     * @deprecated Use new generators logic
600
     */
601
    public function defClassFunction(string $name, string $visibility = 'public', array $parameters = [], array $comments = [], $returnType = null)
602
    {
603
        if ($this->class === null) {
604
            throw new \InvalidArgumentException('Cannot create class function '.$name.' with out class creation');
605
        }
606
607
        $this->defFunction($name, $parameters, $visibility.' ', $comments, $returnType);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::defFunction() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
608
609
        return $this;
610
    }
611
612
    /**
613
     * Add function definition.
614
     *
615
     * @param string $name       Function name
616
     * @param array  $parameters Collection of parameters $typeHint => $paramName
617
     * @param string $prefix     Function prefix
618
     * @param array  $comments   Function multi-line comments
619
     * @param string $returnType Function return type PHP7
620
     *
621
     * @return Generator Chaining
622
     * @deprecated Use new generators logic
623
     */
624
    public function defFunction(string $name, array $parameters = [], string $prefix = '', array $comments = [], string $returnType = null)
625
    {
626
        // Convert parameters to string
627
        $parameterList = array();
628
        foreach ($parameters as $type => $parameter) {
629
            $parameterList[] = (is_string($type) ? $type . ' ' : '') . $parameter;
630
        }
631
        $parameterList = sizeof($parameterList) ? implode(', ', $parameterList) : '';
632
633
        $this
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::multiComment() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method samsonphp\generator\Generator::tabs() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
634
            ->newLine('')
635
            ->multiComment($comments)
636
            ->newLine($prefix . 'function ' . $name . '(' . $parameterList . ')' . ($returnType !== null ? ' : ' . $returnType : ''))
637
            ->newLine('{')
638
            ->tabs('');
639
640
        $this->tabs++;
641
642
        return $this;
643
    }
644
645
    /**
646
     * @see self::defClassFunction with private visibility
647
     *
648
     * @return $this
649
     * @deprecated Use new generators logic
650
     */
651
    public function defPrivateClassFunction(string $name, array $parameters = [], array $comments = [], $returnType = null)
652
    {
653
        return $this->defClassFunction($name, 'private', $parameters, $comments, $returnType);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::defClassFunction() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
654
    }
655
656
    /**
657
     * @see self::defClassFunction with protected visibility
658
     * @deprecated Use new generators logic
659
     * @return $this
660
     */
661
    public function defProtectedClassFunction(string $name, array $parameters = [], array $comments = [], $returnType = null)
662
    {
663
        return $this->defClassFunction($name, 'protected', $parameters, $comments, $returnType);
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::defClassFunction() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
664
    }
665
666
    /**
667
     * Close class function definition.
668
     * @deprecated Use new generators logic
669
     * @return $this Chaining
670
     */
671
    public function endClassFunction()
672
    {
673
        $this->endFunction();
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::endFunction() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
674
675
        return $this;
676
    }
677
678
    /**
679
     * Close current function context.
680
     * @deprecated Use new generators logic
681
     * @return self Chaining
682
     */
683
    public function endFunction()
684
    {
685
        $this->tabs--;
686
687
        return $this->newLine('}');
0 ignored issues
show
Deprecated Code introduced by
The method samsonphp\generator\Generator::newLine() has been deprecated with message: Use new generators logic

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
688
    }
689
}
690
//[PHPCOMPRESSOR(remove,end)]
691