Completed
Push — development ( 006c45...63d178 )
by Andrij
19:41 queued 09:38
created

Banners   F

Complexity

Total Complexity 319

Size/Duplication

Total Lines 2116
Duplicated Lines 31.33 %

Coupling/Cohesion

Components 1
Dependencies 19

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 663
loc 2116
rs 0.6314
wmc 319
lcom 1
cbo 19

91 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isModified() 0 4 1
A isColumnModified() 0 4 2
A getModifiedColumns() 0 4 2
A isNew() 0 4 1
A setNew() 0 4 1
A isDeleted() 0 4 1
A setDeleted() 0 4 1
A resetModified() 10 10 3
B equals() 16 16 5
A getVirtualColumns() 0 4 1
A hasVirtualColumn() 0 4 1
A getVirtualColumn() 8 8 2
A setVirtualColumn() 0 6 1
A log() 0 4 1
A exportTo() 8 8 2
A __sleep() 14 14 2
A getId() 0 4 1
A getPlace() 0 4 1
A getWidth() 0 4 1
A getHeight() 0 4 1
A getEffects() 0 4 1
A getPageType() 0 4 1
A setId() 13 13 3
A setPlace() 13 13 3
A setWidth() 13 13 3
A setHeight() 13 13 3
A setEffects() 13 13 3
A setPageType() 13 13 3
A hasOnlyDefaultValues() 0 5 1
F hydrate() 35 35 15
A ensureConsistency() 0 3 1
B reload() 33 33 6
A delete() 21 21 4
C save() 34 34 8
C doSave() 14 57 19
F doInsert() 0 75 17
A doUpdate() 0 7 1
A getByName() 7 7 1
C getByPosition() 0 26 7
A setByName() 0 6 1
C setByPosition() 0 25 7
C fromArray() 23 23 7
A importFrom() 10 10 2
C buildCriteria() 0 25 7
A buildPkeyCriteria() 0 7 1
A hashCode() 15 15 3
A getPrimaryKey() 0 4 1
A setPrimaryKey() 0 4 1
A isPrimaryKeyNull() 0 4 1
C copyInto() 0 32 7
A copy() 9 9 1
A initRelation() 0 9 3
A clearBannerImages() 0 4 1
A resetPartialBannerImages() 0 4 1
A initBannerImages() 11 11 3
C getBannerImages() 43 43 16
A setBannerImages() 22 22 3
C countBannerImages() 24 24 10
B addBannerImage() 0 17 5
A doAddBannerImage() 0 5 1
A removeBannerImage() 15 15 3
A clearBannersI18ns() 0 4 1
A resetPartialBannersI18ns() 0 4 1
A initBannersI18ns() 11 11 3
C getBannersI18ns() 43 43 16
B setBannersI18ns() 25 25 3
C countBannersI18ns() 24 24 10
B addBannersI18n() 21 21 7
A doAddBannersI18n() 0 5 1
A removeBannersI18n() 15 15 3
A clear() 0 14 1
B clearAllReferences() 0 22 6
A __toString() 0 4 1
A setLocale() 0 6 1
A getLocale() 0 4 1
B getTranslation() 26 26 6
B removeTranslation() 19 19 5
A getCurrentTranslation() 0 4 1
A getName() 0 4 1
A setName() 0 5 1
A preSave() 0 7 2
A postSave() 0 6 2
A preInsert() 0 7 2
A postInsert() 0 6 2
A preUpdate() 0 7 2
A postUpdate() 0 6 2
A preDelete() 0 7 2
A postDelete() 0 6 2
C __call() 29 29 7
C toArray() 0 56 10

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Banners often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Banners, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace xbanners\models\Base;
4
5
use \Exception;
6
use \PDO;
7
use Propel\Runtime\Propel;
8
use Propel\Runtime\ActiveQuery\Criteria;
9
use Propel\Runtime\ActiveQuery\ModelCriteria;
10
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
11
use Propel\Runtime\Collection\Collection;
12
use Propel\Runtime\Collection\ObjectCollection;
13
use Propel\Runtime\Connection\ConnectionInterface;
14
use Propel\Runtime\Exception\BadMethodCallException;
15
use Propel\Runtime\Exception\LogicException;
16
use Propel\Runtime\Exception\PropelException;
17
use Propel\Runtime\Map\TableMap;
18
use Propel\Runtime\Parser\AbstractParser;
19
use xbanners\models\BannerImage as ChildBannerImage;
20
use xbanners\models\BannerImageQuery as ChildBannerImageQuery;
21
use xbanners\models\Banners as ChildBanners;
22
use xbanners\models\BannersI18n as ChildBannersI18n;
23
use xbanners\models\BannersI18nQuery as ChildBannersI18nQuery;
24
use xbanners\models\BannersQuery as ChildBannersQuery;
25
use xbanners\models\Map\BannerImageTableMap;
26
use xbanners\models\Map\BannersI18nTableMap;
27
use xbanners\models\Map\BannersTableMap;
28
29
/**
30
 * Base class that represents a row from the 'banners' table.
31
 *
32
 *
33
 *
34
 * @package    propel.generator.xbanners.models.Base
35
 */
36
abstract class Banners implements ActiveRecordInterface
37
{
0 ignored issues
show
introduced by
Opening brace of a class must be on the same line as the definition
Loading history...
38
    /**
39
     * TableMap class name
40
     */
41
    const TABLE_MAP = '\\xbanners\\models\\Map\\BannersTableMap';
42
43
44
    /**
45
     * attribute to determine if this object has previously been saved.
46
     * @var boolean
47
     */
48
    protected $new = true;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before member var; 2 found
Loading history...
49
50
    /**
51
     * attribute to determine whether this object has been deleted.
52
     * @var boolean
53
     */
54
    protected $deleted = false;
55
56
    /**
57
     * The columns that have been modified in current object.
58
     * Tracking modified columns allows us to only update modified columns.
59
     * @var array
60
     */
61
    protected $modifiedColumns = array();
62
63
    /**
64
     * The (virtual) columns that are added at runtime
65
     * The formatters can add supplementary columns based on a resultset
66
     * @var array
67
     */
68
    protected $virtualColumns = array();
69
70
    /**
71
     * The value for the id field.
72
     *
73
     * @var        int
74
     */
75
    protected $id;
76
77
    /**
78
     * The value for the place field.
79
     *
80
     * @var        string
81
     */
82
    protected $place;
83
84
    /**
85
     * The value for the width field.
86
     *
87
     * @var        int
88
     */
89
    protected $width;
90
91
    /**
92
     * The value for the height field.
93
     *
94
     * @var        int
95
     */
96
    protected $height;
97
98
    /**
99
     * The value for the effects field.
100
     *
101
     * @var        string
102
     */
103
    protected $effects;
104
105
    /**
106
     * The value for the page_type field.
107
     *
108
     * @var        string
109
     */
110
    protected $page_type;
111
112
    /**
113
     * @var        ObjectCollection|ChildBannerImage[] Collection to store aggregation of ChildBannerImage objects.
114
     */
115
    protected $collBannerImages;
116
    protected $collBannerImagesPartial;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
117
118
    /**
119
     * @var        ObjectCollection|ChildBannersI18n[] Collection to store aggregation of ChildBannersI18n objects.
120
     */
121
    protected $collBannersI18ns;
122
    protected $collBannersI18nsPartial;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
123
124
    /**
125
     * Flag to prevent endless save loop, if this object is referenced
126
     * by another object which falls in this transaction.
127
     *
128
     * @var boolean
129
     */
130
    protected $alreadyInSave = false;
131
132
    // i18n behavior
133
134
    /**
135
     * Current locale
136
     * @var        string
137
     */
138
    protected $currentLocale = 'ru';
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before member var; 3 found
Loading history...
139
140
    /**
141
     * Current translation objects
142
     * @var        array[ChildBannersI18n]
143
     */
144
    protected $currentTranslations;
145
146
    /**
147
     * An array of objects scheduled for deletion.
148
     * @var ObjectCollection|ChildBannerImage[]
149
     */
150
    protected $bannerImagesScheduledForDeletion = null;
151
152
    /**
153
     * An array of objects scheduled for deletion.
154
     * @var ObjectCollection|ChildBannersI18n[]
155
     */
156
    protected $bannersI18nsScheduledForDeletion = null;
157
158
    /**
159
     * Initializes internal state of xbanners\models\Base\Banners object.
160
     */
161
    public function __construct()
162
    {
163
    }
164
165
    /**
166
     * Returns whether the object has been modified.
167
     *
168
     * @return boolean True if the object has been modified.
169
     */
170
    public function isModified()
171
    {
172
        return !!$this->modifiedColumns;
173
    }
174
175
    /**
176
     * Has specified column been modified?
177
     *
178
     * @param  string  $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
179
     * @return boolean True if $col has been modified.
180
     */
181
    public function isColumnModified($col)
182
    {
183
        return $this->modifiedColumns && isset($this->modifiedColumns[$col]);
184
    }
185
186
    /**
187
     * Get the columns that have been modified in this object.
188
     * @return array A unique list of the modified column names for this object.
189
     */
190
    public function getModifiedColumns()
191
    {
192
        return $this->modifiedColumns ? array_keys($this->modifiedColumns) : [];
193
    }
194
195
    /**
196
     * Returns whether the object has ever been saved.  This will
197
     * be false, if the object was retrieved from storage or was created
198
     * and then saved.
199
     *
200
     * @return boolean true, if the object has never been persisted.
201
     */
202
    public function isNew()
203
    {
204
        return $this->new;
205
    }
206
207
    /**
208
     * Setter for the isNew attribute.  This method will be called
209
     * by Propel-generated children and objects.
210
     *
211
     * @param boolean $b the state of the object.
212
     */
213
    public function setNew($b)
214
    {
215
        $this->new = (boolean) $b;
216
    }
217
218
    /**
219
     * Whether this object has been deleted.
220
     * @return boolean The deleted state of this object.
221
     */
222
    public function isDeleted()
223
    {
224
        return $this->deleted;
225
    }
226
227
    /**
228
     * Specify whether this object has been deleted.
229
     * @param  boolean $b The deleted state of this object.
230
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
231
     */
232
    public function setDeleted($b)
233
    {
234
        $this->deleted = (boolean) $b;
235
    }
236
237
    /**
238
     * Sets the modified state for the object to be false.
239
     * @param  string $col If supplied, only the specified column is reset.
240
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
241
     */
242 View Code Duplication
    public function resetModified($col = null)
243
    {
244
        if (null !== $col) {
245
            if (isset($this->modifiedColumns[$col])) {
246
                unset($this->modifiedColumns[$col]);
247
            }
248
        } else {
249
            $this->modifiedColumns = array();
250
        }
251
    }
252
253
    /**
254
     * Compares this with another <code>Banners</code> instance.  If
255
     * <code>obj</code> is an instance of <code>Banners</code>, delegates to
256
     * <code>equals(Banners)</code>.  Otherwise, returns <code>false</code>.
257
     *
258
     * @param  mixed   $obj The object to compare to.
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
259
     * @return boolean Whether equal to the object specified.
260
     */
261 View Code Duplication
    public function equals($obj)
262
    {
263
        if (!$obj instanceof static) {
264
            return false;
265
        }
266
267
        if ($this === $obj) {
268
            return true;
269
        }
270
271
        if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) {
272
            return false;
273
        }
274
275
        return $this->getPrimaryKey() === $obj->getPrimaryKey();
276
    }
277
278
    /**
279
     * Get the associative array of the virtual columns in this object
280
     *
281
     * @return array
282
     */
283
    public function getVirtualColumns()
284
    {
285
        return $this->virtualColumns;
286
    }
287
288
    /**
289
     * Checks the existence of a virtual column in this object
290
     *
291
     * @param  string  $name The virtual column name
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
292
     * @return boolean
293
     */
294
    public function hasVirtualColumn($name)
295
    {
296
        return array_key_exists($name, $this->virtualColumns);
297
    }
298
299
    /**
300
     * Get the value of a virtual column in this object
301
     *
302
     * @param  string $name The virtual column name
303
     * @return mixed
304
     *
305
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
306
     */
307 View Code Duplication
    public function getVirtualColumn($name)
308
    {
309
        if (!$this->hasVirtualColumn($name)) {
310
            throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name));
311
        }
312
313
        return $this->virtualColumns[$name];
314
    }
315
316
    /**
317
     * Set the value of a virtual column in this object
318
     *
319
     * @param string $name  The virtual column name
320
     * @param mixed  $value The value to give to the virtual column
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
321
     *
322
     * @return $this|Banners The current object, for fluid interface
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
323
     */
324
    public function setVirtualColumn($name, $value)
325
    {
326
        $this->virtualColumns[$name] = $value;
327
328
        return $this;
329
    }
330
331
    /**
332
     * Logs a message using Propel::log().
333
     *
334
     * @param  string  $msg
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
335
     * @param  int     $priority One of the Propel::LOG_* logging levels
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 5 found
Loading history...
336
     * @return boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
337
     */
338
    protected function log($msg, $priority = Propel::LOG_INFO)
339
    {
340
        return Propel::log(get_class($this) . ': ' . $msg, $priority);
341
    }
342
343
    /**
344
     * Export the current object properties to a string, using a given parser format
345
     * <code>
346
     * $book = BookQuery::create()->findPk(9012);
347
     * echo $book->exportTo('JSON');
348
     *  => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
349
     * </code>
350
     *
351
     * @param  mixed   $parser                 A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
352
     * @param  boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
353
     * @return string  The exported data
354
     */
355 View Code Duplication
    public function exportTo($parser, $includeLazyLoadColumns = true)
356
    {
357
        if (!$parser instanceof AbstractParser) {
358
            $parser = AbstractParser::getParser($parser);
359
        }
360
361
        return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true));
0 ignored issues
show
Bug introduced by
It seems like $this->toArray(\Propel\R...Columns, array(), true) targeting xbanners\models\Base\Banners::toArray() can also be of type string; however, Propel\Runtime\Parser\AbstractParser::fromArray() does only seem to accept array, maybe add an additional type check?

This check looks at variables that 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...
362
    }
363
364
    /**
365
     * Clean up internal collections prior to serializing
366
     * Avoids recursive loops that turn into segmentation faults when serializing
367
     */
368 View Code Duplication
    public function __sleep()
369
    {
370
        $this->clearAllReferences();
371
372
        $cls = new \ReflectionClass($this);
373
        $propertyNames = [];
374
        $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC));
375
376
        foreach($serializableProperties as $property) {
0 ignored issues
show
introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
377
            $propertyNames[] = $property->getName();
378
        }
379
380
        return $propertyNames;
381
    }
382
383
    /**
384
     * Get the [id] column value.
385
     *
386
     * @return int
387
     */
388
    public function getId()
389
    {
390
        return $this->id;
391
    }
392
393
    /**
394
     * Get the [place] column value.
395
     *
396
     * @return string
397
     */
398
    public function getPlace()
399
    {
400
        return $this->place;
401
    }
402
403
    /**
404
     * Get the [width] column value.
405
     *
406
     * @return int
407
     */
408
    public function getWidth()
409
    {
410
        return $this->width;
411
    }
412
413
    /**
414
     * Get the [height] column value.
415
     *
416
     * @return int
417
     */
418
    public function getHeight()
419
    {
420
        return $this->height;
421
    }
422
423
    /**
424
     * Get the [effects] column value.
425
     *
426
     * @return string
427
     */
428
    public function getEffects()
429
    {
430
        return $this->effects;
431
    }
432
433
    /**
434
     * Get the [page_type] column value.
435
     *
436
     * @return string
437
     */
438
    public function getPageType()
439
    {
440
        return $this->page_type;
441
    }
442
443
    /**
444
     * Set the value of [id] column.
445
     *
446
     * @param int $v new value
447
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
448
     */
449 View Code Duplication
    public function setId($v)
450
    {
451
        if ($v !== null) {
452
            $v = (int) $v;
453
        }
454
455
        if ($this->id !== $v) {
456
            $this->id = $v;
457
            $this->modifiedColumns[BannersTableMap::COL_ID] = true;
458
        }
459
460
        return $this;
461
    } // setId()
462
463
    /**
464
     * Set the value of [place] column.
465
     *
466
     * @param string $v new value
467
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
468
     */
469 View Code Duplication
    public function setPlace($v)
470
    {
471
        if ($v !== null) {
472
            $v = (string) $v;
473
        }
474
475
        if ($this->place !== $v) {
476
            $this->place = $v;
477
            $this->modifiedColumns[BannersTableMap::COL_PLACE] = true;
478
        }
479
480
        return $this;
481
    } // setPlace()
482
483
    /**
484
     * Set the value of [width] column.
485
     *
486
     * @param int $v new value
487
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
488
     */
489 View Code Duplication
    public function setWidth($v)
490
    {
491
        if ($v !== null) {
492
            $v = (int) $v;
493
        }
494
495
        if ($this->width !== $v) {
496
            $this->width = $v;
497
            $this->modifiedColumns[BannersTableMap::COL_WIDTH] = true;
498
        }
499
500
        return $this;
501
    } // setWidth()
502
503
    /**
504
     * Set the value of [height] column.
505
     *
506
     * @param int $v new value
507
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
508
     */
509 View Code Duplication
    public function setHeight($v)
510
    {
511
        if ($v !== null) {
512
            $v = (int) $v;
513
        }
514
515
        if ($this->height !== $v) {
516
            $this->height = $v;
517
            $this->modifiedColumns[BannersTableMap::COL_HEIGHT] = true;
518
        }
519
520
        return $this;
521
    } // setHeight()
522
523
    /**
524
     * Set the value of [effects] column.
525
     *
526
     * @param string $v new value
527
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
528
     */
529 View Code Duplication
    public function setEffects($v)
530
    {
531
        if ($v !== null) {
532
            $v = (string) $v;
533
        }
534
535
        if ($this->effects !== $v) {
536
            $this->effects = $v;
537
            $this->modifiedColumns[BannersTableMap::COL_EFFECTS] = true;
538
        }
539
540
        return $this;
541
    } // setEffects()
542
543
    /**
544
     * Set the value of [page_type] column.
545
     *
546
     * @param string $v new value
547
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
548
     */
549 View Code Duplication
    public function setPageType($v)
550
    {
551
        if ($v !== null) {
552
            $v = (string) $v;
553
        }
554
555
        if ($this->page_type !== $v) {
556
            $this->page_type = $v;
557
            $this->modifiedColumns[BannersTableMap::COL_PAGE_TYPE] = true;
558
        }
559
560
        return $this;
561
    } // setPageType()
562
563
    /**
564
     * Indicates whether the columns in this object are only set to default values.
565
     *
566
     * This method can be used in conjunction with isModified() to indicate whether an object is both
567
     * modified _and_ has some values set which are non-default.
568
     *
569
     * @return boolean Whether the columns in this object are only been set with default values.
570
     */
571
    public function hasOnlyDefaultValues()
572
    {
573
        // otherwise, everything was equal, so return TRUE
574
        return true;
575
    } // hasOnlyDefaultValues()
576
577
    /**
578
     * Hydrates (populates) the object variables with values from the database resultset.
579
     *
580
     * An offset (0-based "start column") is specified so that objects can be hydrated
581
     * with a subset of the columns in the resultset rows.  This is needed, for example,
582
     * for results of JOIN queries where the resultset row includes columns from two or
583
     * more tables.
584
     *
585
     * @param array   $row       The row returned by DataFetcher->fetch().
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
586
     * @param int     $startcol  0-based offset column which indicates which restultset column to start with.
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 5 found
Loading history...
587
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
588
     * @param string  $indexType The index type of $row. Mostly DataFetcher->getIndexType().
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
589
                                  One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
590
     *                            TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
591
     *
592
     * @return int             next starting column
593
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
594
     */
595 View Code Duplication
    public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM)
596
    {
597
        try {
598
599
            $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : BannersTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
600
            $this->id = (null !== $col) ? (int) $col : null;
601
602
            $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : BannersTableMap::translateFieldName('Place', TableMap::TYPE_PHPNAME, $indexType)];
603
            $this->place = (null !== $col) ? (string) $col : null;
604
605
            $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : BannersTableMap::translateFieldName('Width', TableMap::TYPE_PHPNAME, $indexType)];
606
            $this->width = (null !== $col) ? (int) $col : null;
607
608
            $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : BannersTableMap::translateFieldName('Height', TableMap::TYPE_PHPNAME, $indexType)];
609
            $this->height = (null !== $col) ? (int) $col : null;
610
611
            $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : BannersTableMap::translateFieldName('Effects', TableMap::TYPE_PHPNAME, $indexType)];
612
            $this->effects = (null !== $col) ? (string) $col : null;
613
614
            $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : BannersTableMap::translateFieldName('PageType', TableMap::TYPE_PHPNAME, $indexType)];
615
            $this->page_type = (null !== $col) ? (string) $col : null;
616
            $this->resetModified();
617
618
            $this->setNew(false);
619
620
            if ($rehydrate) {
621
                $this->ensureConsistency();
622
            }
623
624
            return $startcol + 6; // 6 = BannersTableMap::NUM_HYDRATE_COLUMNS.
625
626
        } catch (Exception $e) {
627
            throw new PropelException(sprintf('Error populating %s object', '\\xbanners\\models\\Banners'), 0, $e);
628
        }
629
    }
630
631
    /**
632
     * Checks and repairs the internal consistency of the object.
633
     *
634
     * This method is executed after an already-instantiated object is re-hydrated
635
     * from the database.  It exists to check any foreign keys to make sure that
636
     * the objects related to the current object are correct based on foreign key.
637
     *
638
     * You can override this method in the stub class, but you should always invoke
639
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
640
     * in case your model changes.
641
     *
642
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
643
     */
644
    public function ensureConsistency()
645
    {
646
    } // ensureConsistency
647
648
    /**
649
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
650
     *
651
     * This will only work if the object has been saved and has a valid primary key set.
652
     *
653
     * @param      boolean $deep (optional) Whether to also de-associated any related objects.
654
     * @param      ConnectionInterface $con (optional) The ConnectionInterface connection to use.
655
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
656
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
657
     */
658 View Code Duplication
    public function reload($deep = false, ConnectionInterface $con = null)
659
    {
660
        if ($this->isDeleted()) {
661
            throw new PropelException("Cannot reload a deleted object.");
662
        }
663
664
        if ($this->isNew()) {
665
            throw new PropelException("Cannot reload an unsaved object.");
666
        }
667
668
        if ($con === null) {
669
            $con = Propel::getServiceContainer()->getReadConnection(BannersTableMap::DATABASE_NAME);
670
        }
671
672
        // We don't need to alter the object instance pool; we're just modifying this instance
673
        // already in the pool.
674
675
        $dataFetcher = ChildBannersQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Propel\Runtime\ActiveQuery\BaseModelCriteria as the method find() does only exist in the following sub-classes of Propel\Runtime\ActiveQuery\BaseModelCriteria: Propel\Runtime\ActiveQuery\ModelCriteria, xbanners\models\BannerImageI18nQuery, xbanners\models\BannerImageQuery, xbanners\models\BannersI18nQuery, xbanners\models\BannersQuery, xbanners\models\Base\BannerImageI18nQuery, xbanners\models\Base\BannerImageQuery, xbanners\models\Base\BannersI18nQuery, xbanners\models\Base\BannersQuery. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
676
        $row = $dataFetcher->fetch();
677
        $dataFetcher->close();
678
        if (!$row) {
679
            throw new PropelException('Cannot find matching row in the database to reload object values.');
680
        }
681
        $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate
682
683
        if ($deep) {  // also de-associate any related objects?
0 ignored issues
show
introduced by
There should be no white space after an opening "{"
Loading history...
684
685
            $this->collBannerImages = null;
686
687
            $this->collBannersI18ns = null;
688
689
        } // if (deep)
690
    }
691
692
    /**
693
     * Removes this object from datastore and sets delete attribute.
694
     *
695
     * @param      ConnectionInterface $con
696
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
697
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
698
     * @see Banners::setDeleted()
699
     * @see Banners::isDeleted()
700
     */
701 View Code Duplication
    public function delete(ConnectionInterface $con = null)
702
    {
703
        if ($this->isDeleted()) {
704
            throw new PropelException("This object has already been deleted.");
705
        }
706
707
        if ($con === null) {
708
            $con = Propel::getServiceContainer()->getWriteConnection(BannersTableMap::DATABASE_NAME);
709
        }
710
711
        $con->transaction(function () use ($con) {
712
            $deleteQuery = ChildBannersQuery::create()
713
                ->filterByPrimaryKey($this->getPrimaryKey());
714
            $ret = $this->preDelete($con);
715
            if ($ret) {
716
                $deleteQuery->delete($con);
717
                $this->postDelete($con);
718
                $this->setDeleted(true);
719
            }
720
        });
721
    }
722
723
    /**
724
     * Persists this object to the database.
725
     *
726
     * If the object is new, it inserts it; otherwise an update is performed.
727
     * All modified related objects will also be persisted in the doSave()
728
     * method.  This method wraps all precipitate database operations in a
729
     * single transaction.
730
     *
731
     * @param      ConnectionInterface $con
732
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
733
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
734
     * @see doSave()
735
     */
736 View Code Duplication
    public function save(ConnectionInterface $con = null)
737
    {
738
        if ($this->isDeleted()) {
739
            throw new PropelException("You cannot save an object that has been deleted.");
740
        }
741
742
        if ($con === null) {
743
            $con = Propel::getServiceContainer()->getWriteConnection(BannersTableMap::DATABASE_NAME);
744
        }
745
746
        return $con->transaction(function () use ($con) {
747
            $ret = $this->preSave($con);
748
            $isInsert = $this->isNew();
749
            if ($isInsert) {
750
                $ret = $ret && $this->preInsert($con);
751
            } else {
752
                $ret = $ret && $this->preUpdate($con);
753
            }
754
            if ($ret) {
755
                $affectedRows = $this->doSave($con);
756
                if ($isInsert) {
757
                    $this->postInsert($con);
758
                } else {
759
                    $this->postUpdate($con);
760
                }
761
                $this->postSave($con);
762
                BannersTableMap::addInstanceToPool($this);
763
            } else {
764
                $affectedRows = 0;
765
            }
766
767
            return $affectedRows;
768
        });
769
    }
770
771
    /**
772
     * Performs the work of inserting or updating the row in the database.
773
     *
774
     * If the object is new, it inserts it; otherwise an update is performed.
775
     * All related objects are also updated in this method.
776
     *
777
     * @param      ConnectionInterface $con
778
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
779
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
780
     * @see save()
781
     */
782
    protected function doSave(ConnectionInterface $con)
783
    {
784
        $affectedRows = 0; // initialize var to track total num of affected rows
785
        if (!$this->alreadyInSave) {
786
            $this->alreadyInSave = true;
787
788
            if ($this->isNew() || $this->isModified()) {
789
                // persist changes
790
                if ($this->isNew()) {
791
                    $this->doInsert($con);
792
                    $affectedRows += 1;
793
                } else {
794
                    $affectedRows += $this->doUpdate($con);
795
                }
796
                $this->resetModified();
797
            }
798
799
            if ($this->bannerImagesScheduledForDeletion !== null) {
800
                if (!$this->bannerImagesScheduledForDeletion->isEmpty()) {
801
                    \xbanners\models\BannerImageQuery::create()
802
                        ->filterByPrimaryKeys($this->bannerImagesScheduledForDeletion->getPrimaryKeys(false))
803
                        ->delete($con);
804
                    $this->bannerImagesScheduledForDeletion = null;
805
                }
806
            }
807
808 View Code Duplication
            if ($this->collBannerImages !== null) {
809
                foreach ($this->collBannerImages as $referrerFK) {
810
                    if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
811
                        $affectedRows += $referrerFK->save($con);
812
                    }
813
                }
814
            }
815
816
            if ($this->bannersI18nsScheduledForDeletion !== null) {
817
                if (!$this->bannersI18nsScheduledForDeletion->isEmpty()) {
818
                    \xbanners\models\BannersI18nQuery::create()
819
                        ->filterByPrimaryKeys($this->bannersI18nsScheduledForDeletion->getPrimaryKeys(false))
820
                        ->delete($con);
821
                    $this->bannersI18nsScheduledForDeletion = null;
822
                }
823
            }
824
825 View Code Duplication
            if ($this->collBannersI18ns !== null) {
826
                foreach ($this->collBannersI18ns as $referrerFK) {
827
                    if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
828
                        $affectedRows += $referrerFK->save($con);
829
                    }
830
                }
831
            }
832
833
            $this->alreadyInSave = false;
834
835
        }
836
837
        return $affectedRows;
838
    } // doSave()
839
840
    /**
841
     * Insert the row in the database.
842
     *
843
     * @param      ConnectionInterface $con
844
     *
845
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
846
     * @see doSave()
847
     */
848
    protected function doInsert(ConnectionInterface $con)
849
    {
850
        $modifiedColumns = array();
851
        $index = 0;
852
853
        $this->modifiedColumns[BannersTableMap::COL_ID] = true;
854
        if (null !== $this->id) {
855
            throw new PropelException('Cannot insert a value for auto-increment primary key (' . BannersTableMap::COL_ID . ')');
856
        }
857
858
         // check the columns in natural order for more readable SQL queries
859
        if ($this->isColumnModified(BannersTableMap::COL_ID)) {
860
            $modifiedColumns[':p' . $index++]  = 'id';
861
        }
862
        if ($this->isColumnModified(BannersTableMap::COL_PLACE)) {
863
            $modifiedColumns[':p' . $index++]  = 'place';
864
        }
865
        if ($this->isColumnModified(BannersTableMap::COL_WIDTH)) {
866
            $modifiedColumns[':p' . $index++]  = 'width';
867
        }
868
        if ($this->isColumnModified(BannersTableMap::COL_HEIGHT)) {
869
            $modifiedColumns[':p' . $index++]  = 'height';
870
        }
871
        if ($this->isColumnModified(BannersTableMap::COL_EFFECTS)) {
872
            $modifiedColumns[':p' . $index++]  = 'effects';
873
        }
874
        if ($this->isColumnModified(BannersTableMap::COL_PAGE_TYPE)) {
875
            $modifiedColumns[':p' . $index++]  = 'page_type';
876
        }
877
878
        $sql = sprintf(
879
            'INSERT INTO banners (%s) VALUES (%s)',
880
            implode(', ', $modifiedColumns),
881
            implode(', ', array_keys($modifiedColumns))
882
        );
883
884
        try {
885
            $stmt = $con->prepare($sql);
886
            foreach ($modifiedColumns as $identifier => $columnName) {
887
                switch ($columnName) {
888
                    case 'id':
889
                        $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
890
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
891
                    case 'place':
892
                        $stmt->bindValue($identifier, $this->place, PDO::PARAM_STR);
893
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
894
                    case 'width':
895
                        $stmt->bindValue($identifier, $this->width, PDO::PARAM_INT);
896
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
897
                    case 'height':
898
                        $stmt->bindValue($identifier, $this->height, PDO::PARAM_INT);
899
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
900
                    case 'effects':
901
                        $stmt->bindValue($identifier, $this->effects, PDO::PARAM_STR);
902
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
903
                    case 'page_type':
904
                        $stmt->bindValue($identifier, $this->page_type, PDO::PARAM_STR);
905
                        break;
906
                }
907
            }
908
            $stmt->execute();
909
        } catch (Exception $e) {
910
            Propel::log($e->getMessage(), Propel::LOG_ERR);
911
            throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
912
        }
913
914
        try {
915
            $pk = $con->lastInsertId();
916
        } catch (Exception $e) {
917
            throw new PropelException('Unable to get autoincrement id.', 0, $e);
918
        }
919
        $this->setId($pk);
920
921
        $this->setNew(false);
922
    }
923
924
    /**
925
     * Update the row in the database.
926
     *
927
     * @param      ConnectionInterface $con
928
     *
929
     * @return Integer Number of updated rows
930
     * @see doSave()
931
     */
932
    protected function doUpdate(ConnectionInterface $con)
933
    {
934
        $selectCriteria = $this->buildPkeyCriteria();
935
        $valuesCriteria = $this->buildCriteria();
936
937
        return $selectCriteria->doUpdate($valuesCriteria, $con);
0 ignored issues
show
Documentation introduced by
$valuesCriteria is of type object<Propel\Runtime\ActiveQuery\Criteria>, but the function expects a array.

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...
938
    }
939
940
    /**
941
     * Retrieves a field from the object by name passed in as a string.
942
     *
943
     * @param      string $name name
944
     * @param      string $type The type of fieldname the $name is of:
945
     *                     one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
946
     *                     TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
947
     *                     Defaults to TableMap::TYPE_PHPNAME.
948
     * @return mixed Value of field.
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use integer|null|string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
949
     */
950 View Code Duplication
    public function getByName($name, $type = TableMap::TYPE_PHPNAME)
951
    {
952
        $pos = BannersTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
953
        $field = $this->getByPosition($pos);
954
955
        return $field;
956
    }
957
958
    /**
959
     * Retrieves a field from the object by Position as specified in the xml schema.
960
     * Zero-based.
961
     *
962
     * @param      int $pos position in xml schema
963
     * @return mixed Value of field at $pos
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use integer|null|string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
964
     */
965
    public function getByPosition($pos)
966
    {
967
        switch ($pos) {
968
            case 0:
969
                return $this->getId();
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
970
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
971
            case 1:
972
                return $this->getPlace();
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
973
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
974
            case 2:
975
                return $this->getWidth();
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
976
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
977
            case 3:
978
                return $this->getHeight();
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
979
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
980
            case 4:
981
                return $this->getEffects();
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
982
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
983
            case 5:
984
                return $this->getPageType();
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
985
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
986
            default:
987
                return null;
988
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
989
        } // switch()
990
    }
991
992
    /**
993
     * Exports the object as an array.
994
     *
995
     * You can specify the key type of the array by passing one of the class
996
     * type constants.
997
     *
998
     * @param     string  $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
999
     *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1000
     *                    Defaults to TableMap::TYPE_PHPNAME.
1001
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
1002
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
1003
     * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
1004
     *
1005
     * @return array an associative array containing the field names (as keys) and field values
0 ignored issues
show
Documentation introduced by
Should the return type not be string|array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1006
     */
1007
    public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
1008
    {
1009
1010
        if (isset($alreadyDumpedObjects['Banners'][$this->hashCode()])) {
1011
            return '*RECURSION*';
1012
        }
1013
        $alreadyDumpedObjects['Banners'][$this->hashCode()] = true;
1014
        $keys = BannersTableMap::getFieldNames($keyType);
1015
        $result = array(
1016
            $keys[0] => $this->getId(),
1017
            $keys[1] => $this->getPlace(),
1018
            $keys[2] => $this->getWidth(),
1019
            $keys[3] => $this->getHeight(),
1020
            $keys[4] => $this->getEffects(),
1021
            $keys[5] => $this->getPageType(),
1022
        );
1023
        $virtualColumns = $this->virtualColumns;
1024
        foreach ($virtualColumns as $key => $virtualColumn) {
1025
            $result[$key] = $virtualColumn;
1026
        }
1027
1028
        if ($includeForeignObjects) {
1029
            if (null !== $this->collBannerImages) {
1030
1031
                switch ($keyType) {
1032
                    case TableMap::TYPE_CAMELNAME:
1033
                        $key = 'bannerImages';
1034
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
1035
                    case TableMap::TYPE_FIELDNAME:
1036
                        $key = 'banner_images';
1037
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
1038
                    default:
1039
                        $key = 'BannerImages';
1040
                }
1041
1042
                $result[$key] = $this->collBannerImages->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
1043
            }
1044
            if (null !== $this->collBannersI18ns) {
1045
1046
                switch ($keyType) {
1047
                    case TableMap::TYPE_CAMELNAME:
1048
                        $key = 'bannersI18ns';
1049
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
1050
                    case TableMap::TYPE_FIELDNAME:
1051
                        $key = 'banners_i18ns';
1052
                        break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
1053
                    default:
1054
                        $key = 'BannersI18ns';
1055
                }
1056
1057
                $result[$key] = $this->collBannersI18ns->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
1058
            }
1059
        }
1060
1061
        return $result;
1062
    }
1063
1064
    /**
1065
     * Sets a field from the object by name passed in as a string.
1066
     *
1067
     * @param  string $name
1068
     * @param  mixed  $value field value
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
1069
     * @param  string $type The type of fieldname the $name is of:
1070
     *                one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
1071
     *                TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1072
     *                Defaults to TableMap::TYPE_PHPNAME.
1073
     * @return $this|\xbanners\models\Banners
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1074
     */
1075
    public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME)
1076
    {
1077
        $pos = BannersTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
1078
1079
        return $this->setByPosition($pos, $value);
1080
    }
1081
1082
    /**
1083
     * Sets a field from the object by Position as specified in the xml schema.
1084
     * Zero-based.
1085
     *
1086
     * @param  int $pos position in xml schema
1087
     * @param  mixed $value field value
1088
     * @return $this|\xbanners\models\Banners
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1089
     */
1090
    public function setByPosition($pos, $value)
1091
    {
1092
        switch ($pos) {
1093
            case 0:
1094
                $this->setId($value);
1095
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
1096
            case 1:
1097
                $this->setPlace($value);
1098
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
1099
            case 2:
1100
                $this->setWidth($value);
1101
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
1102
            case 3:
1103
                $this->setHeight($value);
1104
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
1105
            case 4:
1106
                $this->setEffects($value);
1107
                break;
0 ignored issues
show
Coding Style introduced by
Case breaking statements must be followed by a single blank line
Loading history...
1108
            case 5:
1109
                $this->setPageType($value);
1110
                break;
1111
        } // switch()
1112
1113
        return $this;
1114
    }
1115
1116
    /**
1117
     * Populates the object using an array.
1118
     *
1119
     * This is particularly useful when populating an object from one of the
1120
     * request arrays (e.g. $_POST).  This method goes through the column
1121
     * names, checking to see whether a matching key exists in populated
1122
     * array. If so the setByName() method is called for that column.
1123
     *
1124
     * You can specify the key type of the array by additionally passing one
1125
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1126
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1127
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1128
     *
1129
     * @param      array  $arr     An array to populate the object from.
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
1130
     * @param      string $keyType The type of keys the array uses.
1131
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
1132
     */
1133 View Code Duplication
    public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME)
1134
    {
1135
        $keys = BannersTableMap::getFieldNames($keyType);
1136
1137
        if (array_key_exists($keys[0], $arr)) {
1138
            $this->setId($arr[$keys[0]]);
1139
        }
1140
        if (array_key_exists($keys[1], $arr)) {
1141
            $this->setPlace($arr[$keys[1]]);
1142
        }
1143
        if (array_key_exists($keys[2], $arr)) {
1144
            $this->setWidth($arr[$keys[2]]);
1145
        }
1146
        if (array_key_exists($keys[3], $arr)) {
1147
            $this->setHeight($arr[$keys[3]]);
1148
        }
1149
        if (array_key_exists($keys[4], $arr)) {
1150
            $this->setEffects($arr[$keys[4]]);
1151
        }
1152
        if (array_key_exists($keys[5], $arr)) {
1153
            $this->setPageType($arr[$keys[5]]);
1154
        }
1155
    }
1156
1157
     /**
1158
     * Populate the current object from a string, using a given parser format
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1159
     * <code>
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1160
     * $book = new Book();
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1161
     * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1162
     * </code>
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1163
     *
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1164
     * You can specify the key type of the array by additionally passing one
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1165
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1166
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1167
     * The default key type is the column's TableMap::TYPE_PHPNAME.
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1168
     *
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1169
     * @param mixed $parser A AbstractParser instance,
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1170
     *                       or a format name ('XML', 'YAML', 'JSON', 'CSV')
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
1171
     * @param string $data The source data to import from
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1172
     * @param string $keyType The type of keys the array uses.
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1173
     *
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1174
     * @return $this|\xbanners\models\Banners The current object, for fluid interface
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
introduced by
@return data type must not contain "$"
Loading history...
1175
     */
0 ignored issues
show
Coding Style introduced by
Expected 6 space(s) before asterisk; 5 found
Loading history...
1176 View Code Duplication
    public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME)
1177
    {
1178
        if (!$parser instanceof AbstractParser) {
1179
            $parser = AbstractParser::getParser($parser);
1180
        }
1181
1182
        $this->fromArray($parser->toArray($data), $keyType);
1183
1184
        return $this;
1185
    }
1186
1187
    /**
1188
     * Build a Criteria object containing the values of all modified columns in this object.
1189
     *
1190
     * @return Criteria The Criteria object containing all modified values.
1191
     */
1192
    public function buildCriteria()
1193
    {
1194
        $criteria = new Criteria(BannersTableMap::DATABASE_NAME);
1195
1196
        if ($this->isColumnModified(BannersTableMap::COL_ID)) {
1197
            $criteria->add(BannersTableMap::COL_ID, $this->id);
1198
        }
1199
        if ($this->isColumnModified(BannersTableMap::COL_PLACE)) {
1200
            $criteria->add(BannersTableMap::COL_PLACE, $this->place);
1201
        }
1202
        if ($this->isColumnModified(BannersTableMap::COL_WIDTH)) {
1203
            $criteria->add(BannersTableMap::COL_WIDTH, $this->width);
1204
        }
1205
        if ($this->isColumnModified(BannersTableMap::COL_HEIGHT)) {
1206
            $criteria->add(BannersTableMap::COL_HEIGHT, $this->height);
1207
        }
1208
        if ($this->isColumnModified(BannersTableMap::COL_EFFECTS)) {
1209
            $criteria->add(BannersTableMap::COL_EFFECTS, $this->effects);
1210
        }
1211
        if ($this->isColumnModified(BannersTableMap::COL_PAGE_TYPE)) {
1212
            $criteria->add(BannersTableMap::COL_PAGE_TYPE, $this->page_type);
1213
        }
1214
1215
        return $criteria;
1216
    }
1217
1218
    /**
1219
     * Builds a Criteria object containing the primary key for this object.
1220
     *
1221
     * Unlike buildCriteria() this method includes the primary key values regardless
1222
     * of whether or not they have been modified.
1223
     *
1224
     * @throws LogicException if no primary key is defined
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1225
     *
1226
     * @return Criteria The Criteria object containing value(s) for primary key(s).
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use ChildBannersQuery.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1227
     */
1228
    public function buildPkeyCriteria()
1229
    {
1230
        $criteria = ChildBannersQuery::create();
1231
        $criteria->add(BannersTableMap::COL_ID, $this->id);
1232
1233
        return $criteria;
1234
    }
1235
1236
    /**
1237
     * If the primary key is not null, return the hashcode of the
1238
     * primary key. Otherwise, return the hash code of the object.
1239
     *
1240
     * @return int Hashcode
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1241
     */
1242 View Code Duplication
    public function hashCode()
1243
    {
1244
        $validPk = null !== $this->getId();
1245
1246
        $validPrimaryKeyFKs = 0;
1247
        $primaryKeyFKs = [];
1248
1249
        if ($validPk) {
1250
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
1251
        } elseif ($validPrimaryKeyFKs) {
1252
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
1253
        }
1254
1255
        return spl_object_hash($this);
1256
    }
1257
1258
    /**
1259
     * Returns the primary key for this object (row).
1260
     * @return int
1261
     */
1262
    public function getPrimaryKey()
1263
    {
1264
        return $this->getId();
1265
    }
1266
1267
    /**
1268
     * Generic method to set the primary key (id column).
1269
     *
1270
     * @param       int $key Primary key.
1271
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
1272
     */
1273
    public function setPrimaryKey($key)
1274
    {
1275
        $this->setId($key);
1276
    }
1277
1278
    /**
1279
     * Returns true if the primary key for this object is null.
1280
     * @return boolean
1281
     */
1282
    public function isPrimaryKeyNull()
1283
    {
1284
        return null === $this->getId();
1285
    }
1286
1287
    /**
1288
     * Sets contents of passed object to values from current object.
1289
     *
1290
     * If desired, this method can also make copies of all associated (fkey referrers)
1291
     * objects.
1292
     *
1293
     * @param      object $copyObj An object of \xbanners\models\Banners (or compatible) type.
1294
     * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1295
     * @param      boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1296
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1297
     */
1298
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1299
    {
1300
        $copyObj->setPlace($this->getPlace());
1301
        $copyObj->setWidth($this->getWidth());
1302
        $copyObj->setHeight($this->getHeight());
1303
        $copyObj->setEffects($this->getEffects());
1304
        $copyObj->setPageType($this->getPageType());
1305
1306
        if ($deepCopy) {
1307
            // important: temporarily setNew(false) because this affects the behavior of
1308
            // the getter/setter methods for fkey referrer objects.
1309
            $copyObj->setNew(false);
1310
1311
            foreach ($this->getBannerImages() as $relObj) {
1312
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
0 ignored issues
show
introduced by
There should be no white space after an opening "{"
Loading history...
1313
                    $copyObj->addBannerImage($relObj->copy($deepCopy));
1314
                }
1315
            }
1316
1317
            foreach ($this->getBannersI18ns() as $relObj) {
1318
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
0 ignored issues
show
introduced by
There should be no white space after an opening "{"
Loading history...
1319
                    $copyObj->addBannersI18n($relObj->copy($deepCopy));
1320
                }
1321
            }
1322
1323
        } // if ($deepCopy)
1324
1325
        if ($makeNew) {
1326
            $copyObj->setNew(true);
1327
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1328
        }
1329
    }
1330
1331
    /**
1332
     * Makes a copy of this object that will be inserted as a new row in table when saved.
1333
     * It creates a new object filling in the simple attributes, but skipping any primary
1334
     * keys that are defined for the table.
1335
     *
1336
     * If desired, this method can also make copies of all associated (fkey referrers)
1337
     * objects.
1338
     *
1339
     * @param  boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1340
     * @return \xbanners\models\Banners Clone of current object.
1341
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1342
     */
1343 View Code Duplication
    public function copy($deepCopy = false)
1344
    {
1345
        // we use get_class(), because this might be a subclass
1346
        $clazz = get_class($this);
1347
        $copyObj = new $clazz();
1348
        $this->copyInto($copyObj, $deepCopy);
1349
1350
        return $copyObj;
1351
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
1352
1353
1354
    /**
1355
     * Initializes a collection based on the name of a relation.
1356
     * Avoids crafting an 'init[$relationName]s' method name
1357
     * that wouldn't work when StandardEnglishPluralizer is used.
1358
     *
1359
     * @param      string $relationName The name of the relation to initialize
1360
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
1361
     */
1362
    public function initRelation($relationName)
1363
    {
1364
        if ('BannerImage' == $relationName) {
1365
            return $this->initBannerImages();
1366
        }
1367
        if ('BannersI18n' == $relationName) {
1368
            return $this->initBannersI18ns();
1369
        }
1370
    }
1371
1372
    /**
1373
     * Clears out the collBannerImages collection
1374
     *
1375
     * This does not modify the database; however, it will remove any associated objects, causing
1376
     * them to be refetched by subsequent calls to accessor method.
1377
     *
1378
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
1379
     * @see        addBannerImages()
1380
     */
1381
    public function clearBannerImages()
1382
    {
1383
        $this->collBannerImages = null; // important to set this to NULL since that means it is uninitialized
1384
    }
1385
1386
    /**
1387
     * Reset is the collBannerImages collection loaded partially.
1388
     */
1389
    public function resetPartialBannerImages($v = true)
1390
    {
1391
        $this->collBannerImagesPartial = $v;
1392
    }
1393
1394
    /**
1395
     * Initializes the collBannerImages collection.
1396
     *
1397
     * By default this just sets the collBannerImages collection to an empty array (like clearcollBannerImages());
1398
     * however, you may wish to override this method in your stub class to provide setting appropriate
1399
     * to your application -- for example, setting the initial array to the values stored in database.
1400
     *
1401
     * @param      boolean $overrideExisting If set to true, the method call initializes
1402
     *                                        the collection even if it is not empty
0 ignored issues
show
introduced by
Parameter comment must start with a capital letter
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
1403
     *
1404
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
1405
     */
1406 View Code Duplication
    public function initBannerImages($overrideExisting = true)
1407
    {
1408
        if (null !== $this->collBannerImages && !$overrideExisting) {
1409
            return;
1410
        }
1411
1412
        $collectionClassName = BannerImageTableMap::getTableMap()->getCollectionClassName();
1413
1414
        $this->collBannerImages = new $collectionClassName;
0 ignored issues
show
Coding Style introduced by
Instantiating objects should always be done with parentheses.

The object instantiation should always have parentheses even if no arguments are passed:

new DateTime; // Bad
new DateTime(); // Good
Loading history...
1415
        $this->collBannerImages->setModel('\xbanners\models\BannerImage');
1416
    }
1417
1418
    /**
1419
     * Gets an array of ChildBannerImage objects which contain a foreign key that references this object.
1420
     *
1421
     * If the $criteria is not null, it is used to always fetch the results from the database.
1422
     * Otherwise the results are fetched from the database the first time, then cached.
1423
     * Next time the same method is called without $criteria, the cached collection is returned.
1424
     * If this ChildBanners is new, it will return
1425
     * an empty collection or the current collection; the criteria is ignored on a new object.
1426
     *
1427
     * @param      Criteria $criteria optional Criteria object to narrow the query
1428
     * @param      ConnectionInterface $con optional connection object
1429
     * @return ObjectCollection|ChildBannerImage[] List of ChildBannerImage objects
1430
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1431
     */
1432 View Code Duplication
    public function getBannerImages(Criteria $criteria = null, ConnectionInterface $con = null)
1433
    {
1434
        $partial = $this->collBannerImagesPartial && !$this->isNew();
1435
        if (null === $this->collBannerImages || null !== $criteria  || $partial) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space before logical operator; 2 found
Loading history...
1436
            if ($this->isNew() && null === $this->collBannerImages) {
1437
                // return empty collection
1438
                $this->initBannerImages();
1439
            } else {
1440
                $collBannerImages = ChildBannerImageQuery::create(null, $criteria)
1441
                    ->filterByBanners($this)
0 ignored issues
show
Documentation introduced by
$this is of type this<xbanners\models\Base\Banners>, but the function expects a object<xbanners\models\B...ction\ObjectCollection>.

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...
1442
                    ->find($con);
0 ignored issues
show
Bug introduced by
It seems like $con defined by parameter $con on line 1432 can be null; however, xbanners\models\Base\BannerImageQuery::find() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
1443
1444
                if (null !== $criteria) {
1445
                    if (false !== $this->collBannerImagesPartial && count($collBannerImages)) {
1446
                        $this->initBannerImages(false);
1447
1448
                        foreach ($collBannerImages as $obj) {
1449
                            if (false == $this->collBannerImages->contains($obj)) {
1450
                                $this->collBannerImages->append($obj);
1451
                            }
1452
                        }
1453
1454
                        $this->collBannerImagesPartial = true;
1455
                    }
1456
1457
                    return $collBannerImages;
1458
                }
1459
1460
                if ($partial && $this->collBannerImages) {
1461
                    foreach ($this->collBannerImages as $obj) {
1462
                        if ($obj->isNew()) {
1463
                            $collBannerImages[] = $obj;
1464
                        }
1465
                    }
1466
                }
1467
1468
                $this->collBannerImages = $collBannerImages;
1469
                $this->collBannerImagesPartial = false;
1470
            }
1471
        }
1472
1473
        return $this->collBannerImages;
1474
    }
1475
1476
    /**
1477
     * Sets a collection of ChildBannerImage objects related by a one-to-many relationship
1478
     * to the current object.
1479
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1480
     * and new objects from the given Propel collection.
1481
     *
1482
     * @param      Collection $bannerImages A Propel collection.
1483
     * @param      ConnectionInterface $con Optional connection object
1484
     * @return $this|ChildBanners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1485
     */
1486 View Code Duplication
    public function setBannerImages(Collection $bannerImages, ConnectionInterface $con = null)
1487
    {
1488
        /** @var ChildBannerImage[] $bannerImagesToDelete */
1489
        $bannerImagesToDelete = $this->getBannerImages(new Criteria(), $con)->diff($bannerImages);
1490
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1491
1492
        $this->bannerImagesScheduledForDeletion = $bannerImagesToDelete;
1493
1494
        foreach ($bannerImagesToDelete as $bannerImageRemoved) {
1495
            $bannerImageRemoved->setBanners(null);
1496
        }
1497
1498
        $this->collBannerImages = null;
1499
        foreach ($bannerImages as $bannerImage) {
1500
            $this->addBannerImage($bannerImage);
1501
        }
1502
1503
        $this->collBannerImages = $bannerImages;
0 ignored issues
show
Documentation Bug introduced by
It seems like $bannerImages of type object<Propel\Runtime\Collection\Collection> is incompatible with the declared type object<Propel\Runtime\Co...rs\models\BannerImage>> of property $collBannerImages.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1504
        $this->collBannerImagesPartial = false;
1505
1506
        return $this;
1507
    }
1508
1509
    /**
1510
     * Returns the number of related BannerImage objects.
1511
     *
1512
     * @param      Criteria $criteria
1513
     * @param      boolean $distinct
1514
     * @param      ConnectionInterface $con
1515
     * @return int             Count of related BannerImage objects.
1516
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1517
     */
1518 View Code Duplication
    public function countBannerImages(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
1519
    {
1520
        $partial = $this->collBannerImagesPartial && !$this->isNew();
1521
        if (null === $this->collBannerImages || null !== $criteria || $partial) {
1522
            if ($this->isNew() && null === $this->collBannerImages) {
1523
                return 0;
1524
            }
1525
1526
            if ($partial && !$criteria) {
1527
                return count($this->getBannerImages());
1528
            }
1529
1530
            $query = ChildBannerImageQuery::create(null, $criteria);
1531
            if ($distinct) {
1532
                $query->distinct();
1533
            }
1534
1535
            return $query
1536
                ->filterByBanners($this)
0 ignored issues
show
Documentation introduced by
$this is of type this<xbanners\models\Base\Banners>, but the function expects a object<xbanners\models\B...ction\ObjectCollection>.

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...
1537
                ->count($con);
1538
        }
1539
1540
        return count($this->collBannerImages);
1541
    }
1542
1543
    /**
1544
     * Method called to associate a ChildBannerImage object to this object
1545
     * through the ChildBannerImage foreign key attribute.
1546
     *
1547
     * @param  ChildBannerImage $l ChildBannerImage
1548
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1549
     */
1550
    public function addBannerImage(ChildBannerImage $l)
1551
    {
1552
        if ($this->collBannerImages === null) {
1553
            $this->initBannerImages();
1554
            $this->collBannerImagesPartial = true;
1555
        }
1556
1557
        if (!$this->collBannerImages->contains($l)) {
1558
            $this->doAddBannerImage($l);
1559
1560
            if ($this->bannerImagesScheduledForDeletion and $this->bannerImagesScheduledForDeletion->contains($l)) {
1561
                $this->bannerImagesScheduledForDeletion->remove($this->bannerImagesScheduledForDeletion->search($l));
1562
            }
1563
        }
1564
1565
        return $this;
1566
    }
1567
1568
    /**
1569
     * @param ChildBannerImage $bannerImage The ChildBannerImage object to add.
1570
     */
1571
    protected function doAddBannerImage(ChildBannerImage $bannerImage)
1572
    {
1573
        $this->collBannerImages[]= $bannerImage;
0 ignored issues
show
introduced by
Expected 1 space before "="; 0 found
Loading history...
1574
        $bannerImage->setBanners($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<xbanners\models\Base\Banners>, but the function expects a null|object<xbanners\models\Banners>.

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...
1575
    }
1576
1577
    /**
1578
     * @param  ChildBannerImage $bannerImage The ChildBannerImage object to remove.
1579
     * @return $this|ChildBanners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1580
     */
1581 View Code Duplication
    public function removeBannerImage(ChildBannerImage $bannerImage)
1582
    {
1583
        if ($this->getBannerImages()->contains($bannerImage)) {
1584
            $pos = $this->collBannerImages->search($bannerImage);
1585
            $this->collBannerImages->remove($pos);
1586
            if (null === $this->bannerImagesScheduledForDeletion) {
1587
                $this->bannerImagesScheduledForDeletion = clone $this->collBannerImages;
1588
                $this->bannerImagesScheduledForDeletion->clear();
1589
            }
1590
            $this->bannerImagesScheduledForDeletion[]= clone $bannerImage;
0 ignored issues
show
introduced by
Expected 1 space before "="; 0 found
Loading history...
1591
            $bannerImage->setBanners(null);
1592
        }
1593
1594
        return $this;
1595
    }
1596
1597
    /**
1598
     * Clears out the collBannersI18ns collection
1599
     *
1600
     * This does not modify the database; however, it will remove any associated objects, causing
1601
     * them to be refetched by subsequent calls to accessor method.
1602
     *
1603
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
1604
     * @see        addBannersI18ns()
1605
     */
1606
    public function clearBannersI18ns()
1607
    {
1608
        $this->collBannersI18ns = null; // important to set this to NULL since that means it is uninitialized
1609
    }
1610
1611
    /**
1612
     * Reset is the collBannersI18ns collection loaded partially.
1613
     */
1614
    public function resetPartialBannersI18ns($v = true)
1615
    {
1616
        $this->collBannersI18nsPartial = $v;
1617
    }
1618
1619
    /**
1620
     * Initializes the collBannersI18ns collection.
1621
     *
1622
     * By default this just sets the collBannersI18ns collection to an empty array (like clearcollBannersI18ns());
1623
     * however, you may wish to override this method in your stub class to provide setting appropriate
1624
     * to your application -- for example, setting the initial array to the values stored in database.
1625
     *
1626
     * @param      boolean $overrideExisting If set to true, the method call initializes
1627
     *                                        the collection even if it is not empty
0 ignored issues
show
introduced by
Parameter comment must start with a capital letter
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
1628
     *
1629
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
1630
     */
1631 View Code Duplication
    public function initBannersI18ns($overrideExisting = true)
1632
    {
1633
        if (null !== $this->collBannersI18ns && !$overrideExisting) {
1634
            return;
1635
        }
1636
1637
        $collectionClassName = BannersI18nTableMap::getTableMap()->getCollectionClassName();
1638
1639
        $this->collBannersI18ns = new $collectionClassName;
0 ignored issues
show
Coding Style introduced by
Instantiating objects should always be done with parentheses.

The object instantiation should always have parentheses even if no arguments are passed:

new DateTime; // Bad
new DateTime(); // Good
Loading history...
1640
        $this->collBannersI18ns->setModel('\xbanners\models\BannersI18n');
1641
    }
1642
1643
    /**
1644
     * Gets an array of ChildBannersI18n objects which contain a foreign key that references this object.
1645
     *
1646
     * If the $criteria is not null, it is used to always fetch the results from the database.
1647
     * Otherwise the results are fetched from the database the first time, then cached.
1648
     * Next time the same method is called without $criteria, the cached collection is returned.
1649
     * If this ChildBanners is new, it will return
1650
     * an empty collection or the current collection; the criteria is ignored on a new object.
1651
     *
1652
     * @param      Criteria $criteria optional Criteria object to narrow the query
1653
     * @param      ConnectionInterface $con optional connection object
1654
     * @return ObjectCollection|ChildBannersI18n[] List of ChildBannersI18n objects
1655
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1656
     */
1657 View Code Duplication
    public function getBannersI18ns(Criteria $criteria = null, ConnectionInterface $con = null)
1658
    {
1659
        $partial = $this->collBannersI18nsPartial && !$this->isNew();
1660
        if (null === $this->collBannersI18ns || null !== $criteria  || $partial) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space before logical operator; 2 found
Loading history...
1661
            if ($this->isNew() && null === $this->collBannersI18ns) {
1662
                // return empty collection
1663
                $this->initBannersI18ns();
1664
            } else {
1665
                $collBannersI18ns = ChildBannersI18nQuery::create(null, $criteria)
1666
                    ->filterByBanners($this)
0 ignored issues
show
Documentation introduced by
$this is of type this<xbanners\models\Base\Banners>, but the function expects a object<xbanners\models\B...ction\ObjectCollection>.

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...
1667
                    ->find($con);
0 ignored issues
show
Bug introduced by
It seems like $con defined by parameter $con on line 1657 can be null; however, xbanners\models\Base\BannersI18nQuery::find() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
1668
1669
                if (null !== $criteria) {
1670
                    if (false !== $this->collBannersI18nsPartial && count($collBannersI18ns)) {
1671
                        $this->initBannersI18ns(false);
1672
1673
                        foreach ($collBannersI18ns as $obj) {
1674
                            if (false == $this->collBannersI18ns->contains($obj)) {
1675
                                $this->collBannersI18ns->append($obj);
1676
                            }
1677
                        }
1678
1679
                        $this->collBannersI18nsPartial = true;
1680
                    }
1681
1682
                    return $collBannersI18ns;
1683
                }
1684
1685
                if ($partial && $this->collBannersI18ns) {
1686
                    foreach ($this->collBannersI18ns as $obj) {
1687
                        if ($obj->isNew()) {
1688
                            $collBannersI18ns[] = $obj;
1689
                        }
1690
                    }
1691
                }
1692
1693
                $this->collBannersI18ns = $collBannersI18ns;
1694
                $this->collBannersI18nsPartial = false;
1695
            }
1696
        }
1697
1698
        return $this->collBannersI18ns;
1699
    }
1700
1701
    /**
1702
     * Sets a collection of ChildBannersI18n objects related by a one-to-many relationship
1703
     * to the current object.
1704
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1705
     * and new objects from the given Propel collection.
1706
     *
1707
     * @param      Collection $bannersI18ns A Propel collection.
1708
     * @param      ConnectionInterface $con Optional connection object
1709
     * @return $this|ChildBanners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1710
     */
1711 View Code Duplication
    public function setBannersI18ns(Collection $bannersI18ns, ConnectionInterface $con = null)
1712
    {
1713
        /** @var ChildBannersI18n[] $bannersI18nsToDelete */
1714
        $bannersI18nsToDelete = $this->getBannersI18ns(new Criteria(), $con)->diff($bannersI18ns);
1715
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1716
1717
        //since at least one column in the foreign key is at the same time a PK
1718
        //we can not just set a PK to NULL in the lines below. We have to store
1719
        //a backup of all values, so we are able to manipulate these items based on the onDelete value later.
1720
        $this->bannersI18nsScheduledForDeletion = clone $bannersI18nsToDelete;
1721
1722
        foreach ($bannersI18nsToDelete as $bannersI18nRemoved) {
1723
            $bannersI18nRemoved->setBanners(null);
1724
        }
1725
1726
        $this->collBannersI18ns = null;
1727
        foreach ($bannersI18ns as $bannersI18n) {
1728
            $this->addBannersI18n($bannersI18n);
1729
        }
1730
1731
        $this->collBannersI18ns = $bannersI18ns;
0 ignored issues
show
Documentation Bug introduced by
It seems like $bannersI18ns of type object<Propel\Runtime\Collection\Collection> is incompatible with the declared type object<Propel\Runtime\Co...rs\models\BannersI18n>> of property $collBannersI18ns.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1732
        $this->collBannersI18nsPartial = false;
1733
1734
        return $this;
1735
    }
1736
1737
    /**
1738
     * Returns the number of related BannersI18n objects.
1739
     *
1740
     * @param      Criteria $criteria
1741
     * @param      boolean $distinct
1742
     * @param      ConnectionInterface $con
1743
     * @return int             Count of related BannersI18n objects.
1744
     * @throws PropelException
0 ignored issues
show
introduced by
Comment missing or not on the next line for @throws tag in function comment
Loading history...
1745
     */
1746 View Code Duplication
    public function countBannersI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
1747
    {
1748
        $partial = $this->collBannersI18nsPartial && !$this->isNew();
1749
        if (null === $this->collBannersI18ns || null !== $criteria || $partial) {
1750
            if ($this->isNew() && null === $this->collBannersI18ns) {
1751
                return 0;
1752
            }
1753
1754
            if ($partial && !$criteria) {
1755
                return count($this->getBannersI18ns());
1756
            }
1757
1758
            $query = ChildBannersI18nQuery::create(null, $criteria);
1759
            if ($distinct) {
1760
                $query->distinct();
1761
            }
1762
1763
            return $query
1764
                ->filterByBanners($this)
0 ignored issues
show
Documentation introduced by
$this is of type this<xbanners\models\Base\Banners>, but the function expects a object<xbanners\models\B...ction\ObjectCollection>.

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...
1765
                ->count($con);
1766
        }
1767
1768
        return count($this->collBannersI18ns);
1769
    }
1770
1771
    /**
1772
     * Method called to associate a ChildBannersI18n object to this object
1773
     * through the ChildBannersI18n foreign key attribute.
1774
     *
1775
     * @param  ChildBannersI18n $l ChildBannersI18n
1776
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1777
     */
1778 View Code Duplication
    public function addBannersI18n(ChildBannersI18n $l)
1779
    {
1780
        if ($l && $locale = $l->getLocale()) {
1781
            $this->setLocale($locale);
1782
            $this->currentTranslations[$locale] = $l;
1783
        }
1784
        if ($this->collBannersI18ns === null) {
1785
            $this->initBannersI18ns();
1786
            $this->collBannersI18nsPartial = true;
1787
        }
1788
1789
        if (!$this->collBannersI18ns->contains($l)) {
1790
            $this->doAddBannersI18n($l);
1791
1792
            if ($this->bannersI18nsScheduledForDeletion and $this->bannersI18nsScheduledForDeletion->contains($l)) {
1793
                $this->bannersI18nsScheduledForDeletion->remove($this->bannersI18nsScheduledForDeletion->search($l));
1794
            }
1795
        }
1796
1797
        return $this;
1798
    }
1799
1800
    /**
1801
     * @param ChildBannersI18n $bannersI18n The ChildBannersI18n object to add.
1802
     */
1803
    protected function doAddBannersI18n(ChildBannersI18n $bannersI18n)
1804
    {
1805
        $this->collBannersI18ns[]= $bannersI18n;
0 ignored issues
show
introduced by
Expected 1 space before "="; 0 found
Loading history...
1806
        $bannersI18n->setBanners($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<xbanners\models\Base\Banners>, but the function expects a null|object<xbanners\models\Banners>.

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...
1807
    }
1808
1809
    /**
1810
     * @param  ChildBannersI18n $bannersI18n The ChildBannersI18n object to remove.
1811
     * @return $this|ChildBanners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1812
     */
1813 View Code Duplication
    public function removeBannersI18n(ChildBannersI18n $bannersI18n)
1814
    {
1815
        if ($this->getBannersI18ns()->contains($bannersI18n)) {
1816
            $pos = $this->collBannersI18ns->search($bannersI18n);
1817
            $this->collBannersI18ns->remove($pos);
1818
            if (null === $this->bannersI18nsScheduledForDeletion) {
1819
                $this->bannersI18nsScheduledForDeletion = clone $this->collBannersI18ns;
1820
                $this->bannersI18nsScheduledForDeletion->clear();
1821
            }
1822
            $this->bannersI18nsScheduledForDeletion[]= clone $bannersI18n;
0 ignored issues
show
introduced by
Expected 1 space before "="; 0 found
Loading history...
1823
            $bannersI18n->setBanners(null);
1824
        }
1825
1826
        return $this;
1827
    }
1828
1829
    /**
1830
     * Clears the current object, sets all attributes to their default values and removes
1831
     * outgoing references as well as back-references (from other objects to this one. Results probably in a database
1832
     * change of those foreign objects when you call `save` there).
1833
     */
1834
    public function clear()
1835
    {
1836
        $this->id = null;
1837
        $this->place = null;
1838
        $this->width = null;
1839
        $this->height = null;
1840
        $this->effects = null;
1841
        $this->page_type = null;
1842
        $this->alreadyInSave = false;
1843
        $this->clearAllReferences();
1844
        $this->resetModified();
1845
        $this->setNew(true);
1846
        $this->setDeleted(false);
1847
    }
1848
1849
    /**
1850
     * Resets all references and back-references to other model objects or collections of model objects.
1851
     *
1852
     * This method is used to reset all php object references (not the actual reference in the database).
1853
     * Necessary for object serialisation.
1854
     *
1855
     * @param      boolean $deep Whether to also clear the references on all referrer objects.
1856
     */
1857
    public function clearAllReferences($deep = false)
1858
    {
1859
        if ($deep) {
1860
            if ($this->collBannerImages) {
1861
                foreach ($this->collBannerImages as $o) {
1862
                    $o->clearAllReferences($deep);
1863
                }
1864
            }
1865
            if ($this->collBannersI18ns) {
1866
                foreach ($this->collBannersI18ns as $o) {
1867
                    $o->clearAllReferences($deep);
1868
                }
1869
            }
1870
        } // if ($deep)
1871
1872
        // i18n behavior
1873
        $this->currentLocale = 'ru';
1874
        $this->currentTranslations = null;
1875
1876
        $this->collBannerImages = null;
1877
        $this->collBannersI18ns = null;
1878
    }
1879
1880
    /**
1881
     * Return the string representation of this object
1882
     *
1883
     * @return string
1884
     */
1885
    public function __toString()
1886
    {
1887
        return (string) $this->exportTo(BannersTableMap::DEFAULT_STRING_FORMAT);
1888
    }
1889
1890
    // i18n behavior
1891
1892
    /**
1893
     * Sets the locale for translations
1894
     *
1895
     * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
1896
     *
1897
     * @return    $this|ChildBanners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1898
     */
1899
    public function setLocale($locale = 'ru')
1900
    {
1901
        $this->currentLocale = $locale;
1902
1903
        return $this;
1904
    }
1905
1906
    /**
1907
     * Gets the locale for translations
1908
     *
1909
     * @return    string $locale Locale to use for the translation, e.g. 'fr_FR'
1910
     */
1911
    public function getLocale()
1912
    {
1913
        return $this->currentLocale;
1914
    }
1915
1916
    /**
1917
     * Returns the current translation for a given locale
1918
     *
1919
     * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
1920
     * @param     ConnectionInterface $con an optional connection object
1921
     *
1922
     * @return ChildBannersI18n */
1923 View Code Duplication
    public function getTranslation($locale = 'ru', ConnectionInterface $con = null)
1924
    {
1925
        if (!isset($this->currentTranslations[$locale])) {
1926
            if (null !== $this->collBannersI18ns) {
1927
                foreach ($this->collBannersI18ns as $translation) {
1928
                    if ($translation->getLocale() == $locale) {
1929
                        $this->currentTranslations[$locale] = $translation;
1930
1931
                        return $translation;
1932
                    }
1933
                }
1934
            }
1935
            if ($this->isNew()) {
1936
                $translation = new ChildBannersI18n();
1937
                $translation->setLocale($locale);
1938
            } else {
1939
                $translation = ChildBannersI18nQuery::create()
1940
                    ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
1941
                    ->findOneOrCreate($con);
0 ignored issues
show
Bug introduced by
It seems like $con defined by parameter $con on line 1923 can be null; however, xbanners\models\Base\Ban...uery::findOneOrCreate() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
1942
                $this->currentTranslations[$locale] = $translation;
1943
            }
1944
            $this->addBannersI18n($translation);
1945
        }
1946
1947
        return $this->currentTranslations[$locale];
1948
    }
1949
1950
    /**
1951
     * Remove the translation for a given locale
1952
     *
1953
     * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
1954
     * @param     ConnectionInterface $con an optional connection object
1955
     *
1956
     * @return    $this|ChildBanners The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
1957
     */
1958 View Code Duplication
    public function removeTranslation($locale = 'ru', ConnectionInterface $con = null)
1959
    {
1960
        if (!$this->isNew()) {
1961
            ChildBannersI18nQuery::create()
1962
                ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
1963
                ->delete($con);
1964
        }
1965
        if (isset($this->currentTranslations[$locale])) {
1966
            unset($this->currentTranslations[$locale]);
1967
        }
1968
        foreach ($this->collBannersI18ns as $key => $translation) {
1969
            if ($translation->getLocale() == $locale) {
1970
                unset($this->collBannersI18ns[$key]);
1971
                break;
1972
            }
1973
        }
1974
1975
        return $this;
1976
    }
1977
1978
    /**
1979
     * Returns the current translation
1980
     *
1981
     * @param     ConnectionInterface $con an optional connection object
1982
     *
1983
     * @return ChildBannersI18n */
1984
    public function getCurrentTranslation(ConnectionInterface $con = null)
1985
    {
1986
        return $this->getTranslation($this->getLocale(), $con);
1987
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
1988
1989
1990
        /**
1991
         * Get the [name] column value.
1992
         *
1993
         * @return string
1994
         */
1995
        public function getName()
1996
        {
1997
        return $this->getCurrentTranslation()->getName();
1998
    }
0 ignored issues
show
introduced by
Closing brace indented incorrectly; expected 8 spaces, found 4
Loading history...
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
1999
2000
2001
        /**
2002
         * Set the value of [name] column.
2003
         *
2004
         * @param string $v new value
2005
         * @return $this|\xbanners\models\BannersI18n The current object (for fluent API support)
0 ignored issues
show
introduced by
@return data type must not contain "$"
Loading history...
2006
         */
2007
        public function setName($v)
2008
        {    $this->getCurrentTranslation()->setName($v);
0 ignored issues
show
introduced by
Opening brace must be the last content on the line
Loading history...
introduced by
There should be no white space after an opening "{"
Loading history...
2009
2010
        return $this;
2011
    }
0 ignored issues
show
introduced by
Closing brace indented incorrectly; expected 8 spaces, found 4
Loading history...
2012
2013
    /**
2014
     * Code to be run before persisting the object
2015
     * @param  ConnectionInterface $con
2016
     * @return boolean
2017
     */
2018
    public function preSave(ConnectionInterface $con = null)
2019
    {
2020
        if (is_callable('parent::preSave')) {
2021
            return parent::preSave($con);
2022
        }
2023
        return true;
2024
    }
2025
2026
    /**
2027
     * Code to be run after persisting the object
2028
     * @param ConnectionInterface $con
2029
     */
2030
    public function postSave(ConnectionInterface $con = null)
2031
    {
2032
        if (is_callable('parent::postSave')) {
2033
            parent::postSave($con);
2034
        }
2035
    }
2036
2037
    /**
2038
     * Code to be run before inserting to database
2039
     * @param  ConnectionInterface $con
2040
     * @return boolean
2041
     */
2042
    public function preInsert(ConnectionInterface $con = null)
2043
    {
2044
        if (is_callable('parent::preInsert')) {
2045
            return parent::preInsert($con);
2046
        }
2047
        return true;
2048
    }
2049
2050
    /**
2051
     * Code to be run after inserting to database
2052
     * @param ConnectionInterface $con
2053
     */
2054
    public function postInsert(ConnectionInterface $con = null)
2055
    {
2056
        if (is_callable('parent::postInsert')) {
2057
            parent::postInsert($con);
2058
        }
2059
    }
2060
2061
    /**
2062
     * Code to be run before updating the object in database
2063
     * @param  ConnectionInterface $con
2064
     * @return boolean
2065
     */
2066
    public function preUpdate(ConnectionInterface $con = null)
2067
    {
2068
        if (is_callable('parent::preUpdate')) {
2069
            return parent::preUpdate($con);
2070
        }
2071
        return true;
2072
    }
2073
2074
    /**
2075
     * Code to be run after updating the object in database
2076
     * @param ConnectionInterface $con
2077
     */
2078
    public function postUpdate(ConnectionInterface $con = null)
2079
    {
2080
        if (is_callable('parent::postUpdate')) {
2081
            parent::postUpdate($con);
2082
        }
2083
    }
2084
2085
    /**
2086
     * Code to be run before deleting the object in database
2087
     * @param  ConnectionInterface $con
2088
     * @return boolean
2089
     */
2090
    public function preDelete(ConnectionInterface $con = null)
2091
    {
2092
        if (is_callable('parent::preDelete')) {
2093
            return parent::preDelete($con);
2094
        }
2095
        return true;
2096
    }
2097
2098
    /**
2099
     * Code to be run after deleting the object in database
2100
     * @param ConnectionInterface $con
2101
     */
2102
    public function postDelete(ConnectionInterface $con = null)
2103
    {
2104
        if (is_callable('parent::postDelete')) {
2105
            parent::postDelete($con);
2106
        }
2107
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
2108
2109
2110
    /**
2111
     * Derived method to catches calls to undefined methods.
2112
     *
2113
     * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
2114
     * Allows to define default __call() behavior if you overwrite __call()
2115
     *
2116
     * @param string $name
2117
     * @param mixed  $params
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
2118
     *
2119
     * @return array|string
2120
     */
2121 View Code Duplication
    public function __call($name, $params)
2122
    {
2123
        if (0 === strpos($name, 'get')) {
2124
            $virtualColumn = substr($name, 3);
2125
            if ($this->hasVirtualColumn($virtualColumn)) {
2126
                return $this->getVirtualColumn($virtualColumn);
2127
            }
2128
2129
            $virtualColumn = lcfirst($virtualColumn);
2130
            if ($this->hasVirtualColumn($virtualColumn)) {
2131
                return $this->getVirtualColumn($virtualColumn);
2132
            }
2133
        }
2134
2135
        if (0 === strpos($name, 'from')) {
2136
            $format = substr($name, 4);
2137
2138
            return $this->importFrom($format, reset($params));
2139
        }
2140
2141
        if (0 === strpos($name, 'to')) {
2142
            $format = substr($name, 2);
2143
            $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
2144
2145
            return $this->exportTo($format, $includeLazyLoadColumns);
2146
        }
2147
2148
        throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
2149
    }
2150
2151
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
2152