Banners   F
last analyzed

Complexity

Total Complexity 320

Size/Duplication

Total Lines 2120
Duplicated Lines 36.79 %

Coupling/Cohesion

Components 1
Dependencies 20

Importance

Changes 0
Metric Value
dl 780
loc 2120
rs 0.8
c 0
b 0
f 0
wmc 320
lcom 1
cbo 20

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
A 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
B save() 38 38 9
D doSave() 57 57 19
F doInsert() 0 75 17
A doUpdate() 0 7 1
A getByName() 7 7 1
B getByPosition() 0 26 7
B toArray() 56 56 10
A setByName() 0 6 1
B setByPosition() 0 25 7
B fromArray() 23 23 7
A importFrom() 10 10 2
B 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
B 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
B countBannerImages() 24 24 10
A 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
A setBannersI18ns() 25 25 3
B countBannersI18ns() 24 24 10
B addBannersI18n() 21 21 7
A doAddBannersI18n() 0 5 1
A removeBannersI18n() 15 15 3
A clear() 14 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
A 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
B __call() 29 29 7

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 CMSFactory\PropelBaseModelClass;
8
use Propel\Runtime\Propel;
9
use Propel\Runtime\ActiveQuery\Criteria;
10
use Propel\Runtime\ActiveQuery\ModelCriteria;
11
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
12
use Propel\Runtime\Collection\Collection;
13
use Propel\Runtime\Collection\ObjectCollection;
14
use Propel\Runtime\Connection\ConnectionInterface;
15
use Propel\Runtime\Exception\BadMethodCallException;
16
use Propel\Runtime\Exception\LogicException;
17
use Propel\Runtime\Exception\PropelException;
18
use Propel\Runtime\Map\TableMap;
19
use Propel\Runtime\Parser\AbstractParser;
20
use xbanners\models\BannerImage as ChildBannerImage;
21
use xbanners\models\BannerImageQuery as ChildBannerImageQuery;
22
use xbanners\models\Banners as ChildBanners;
23
use xbanners\models\BannersI18n as ChildBannersI18n;
24
use xbanners\models\BannersI18nQuery as ChildBannersI18nQuery;
25
use xbanners\models\BannersQuery as ChildBannersQuery;
26
use xbanners\models\Map\BannerImageTableMap;
27
use xbanners\models\Map\BannersI18nTableMap;
28
use xbanners\models\Map\BannersTableMap;
29
30
/**
31
 * Base class that represents a row from the 'banners' table.
32
 *
33
 *
34
 *
35
 * @package    propel.generator.xbanners.models.Base
36
 */
37
abstract class Banners extends PropelBaseModelClass implements ActiveRecordInterface
38
{
39
    /**
40
     * TableMap class name
41
     */
42
    const TABLE_MAP = '\\xbanners\\models\\Map\\BannersTableMap';
43
44
45
    /**
46
     * attribute to determine if this object has previously been saved.
47
     * @var boolean
48
     */
49
    protected $new = true;
50
51
    /**
52
     * attribute to determine whether this object has been deleted.
53
     * @var boolean
54
     */
55
    protected $deleted = false;
56
57
    /**
58
     * The columns that have been modified in current object.
59
     * Tracking modified columns allows us to only update modified columns.
60
     * @var array
61
     */
62
    protected $modifiedColumns = array();
63
64
    /**
65
     * The (virtual) columns that are added at runtime
66
     * The formatters can add supplementary columns based on a resultset
67
     * @var array
68
     */
69
    protected $virtualColumns = array();
70
71
    /**
72
     * The value for the id field.
73
     *
74
     * @var        int
75
     */
76
    protected $id;
77
78
    /**
79
     * The value for the place field.
80
     *
81
     * @var        string
82
     */
83
    protected $place;
84
85
    /**
86
     * The value for the width field.
87
     *
88
     * @var        int
89
     */
90
    protected $width;
91
92
    /**
93
     * The value for the height field.
94
     *
95
     * @var        int
96
     */
97
    protected $height;
98
99
    /**
100
     * The value for the effects field.
101
     *
102
     * @var        string
103
     */
104
    protected $effects;
105
106
    /**
107
     * The value for the page_type field.
108
     *
109
     * @var        string
110
     */
111
    protected $page_type;
112
113
    /**
114
     * @var        ObjectCollection|ChildBannerImage[] Collection to store aggregation of ChildBannerImage objects.
115
     */
116
    protected $collBannerImages;
117
    protected $collBannerImagesPartial;
118
119
    /**
120
     * @var        ObjectCollection|ChildBannersI18n[] Collection to store aggregation of ChildBannersI18n objects.
121
     */
122
    protected $collBannersI18ns;
123
    protected $collBannersI18nsPartial;
124
125
    /**
126
     * Flag to prevent endless save loop, if this object is referenced
127
     * by another object which falls in this transaction.
128
     *
129
     * @var boolean
130
     */
131
    protected $alreadyInSave = false;
132
133
    // i18n behavior
134
135
    /**
136
     * Current locale
137
     * @var        string
138
     */
139
    protected $currentLocale = 'ru';
140
141
    /**
142
     * Current translation objects
143
     * @var        array[ChildBannersI18n]
144
     */
145
    protected $currentTranslations;
146
147
    /**
148
     * An array of objects scheduled for deletion.
149
     * @var ObjectCollection|ChildBannerImage[]
150
     */
151
    protected $bannerImagesScheduledForDeletion = null;
152
153
    /**
154
     * An array of objects scheduled for deletion.
155
     * @var ObjectCollection|ChildBannersI18n[]
156
     */
157
    protected $bannersI18nsScheduledForDeletion = null;
158
159
    /**
160
     * Initializes internal state of xbanners\models\Base\Banners object.
161
     */
162
    public function __construct()
163
    {
164
    }
165
166
    /**
167
     * Returns whether the object has been modified.
168
     *
169
     * @return boolean True if the object has been modified.
170
     */
171
    public function isModified()
172
    {
173
        return !!$this->modifiedColumns;
174
    }
175
176
    /**
177
     * Has specified column been modified?
178
     *
179
     * @param  string  $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID
180
     * @return boolean True if $col has been modified.
181
     */
182
    public function isColumnModified($col)
183
    {
184
        return $this->modifiedColumns && isset($this->modifiedColumns[$col]);
185
    }
186
187
    /**
188
     * Get the columns that have been modified in this object.
189
     * @return array A unique list of the modified column names for this object.
190
     */
191
    public function getModifiedColumns()
192
    {
193
        return $this->modifiedColumns ? array_keys($this->modifiedColumns) : [];
194
    }
195
196
    /**
197
     * Returns whether the object has ever been saved.  This will
198
     * be false, if the object was retrieved from storage or was created
199
     * and then saved.
200
     *
201
     * @return boolean true, if the object has never been persisted.
202
     */
203
    public function isNew()
204
    {
205
        return $this->new;
206
    }
207
208
    /**
209
     * Setter for the isNew attribute.  This method will be called
210
     * by Propel-generated children and objects.
211
     *
212
     * @param boolean $b the state of the object.
213
     */
214
    public function setNew($b)
215
    {
216
        $this->new = (boolean) $b;
217
    }
218
219
    /**
220
     * Whether this object has been deleted.
221
     * @return boolean The deleted state of this object.
222
     */
223
    public function isDeleted()
224
    {
225
        return $this->deleted;
226
    }
227
228
    /**
229
     * Specify whether this object has been deleted.
230
     * @param  boolean $b The deleted state of this object.
231
     * @return void
232
     */
233
    public function setDeleted($b)
234
    {
235
        $this->deleted = (boolean) $b;
236
    }
237
238
    /**
239
     * Sets the modified state for the object to be false.
240
     * @param  string $col If supplied, only the specified column is reset.
241
     * @return void
242
     */
243 View Code Duplication
    public function resetModified($col = null)
244
    {
245
        if (null !== $col) {
246
            if (isset($this->modifiedColumns[$col])) {
247
                unset($this->modifiedColumns[$col]);
248
            }
249
        } else {
250
            $this->modifiedColumns = array();
251
        }
252
    }
253
254
    /**
255
     * Compares this with another <code>Banners</code> instance.  If
256
     * <code>obj</code> is an instance of <code>Banners</code>, delegates to
257
     * <code>equals(Banners)</code>.  Otherwise, returns <code>false</code>.
258
     *
259
     * @param  mixed   $obj The object to compare to.
260
     * @return boolean Whether equal to the object specified.
261
     */
262 View Code Duplication
    public function equals($obj)
263
    {
264
        if (!$obj instanceof static) {
265
            return false;
266
        }
267
268
        if ($this === $obj) {
269
            return true;
270
        }
271
272
        if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) {
273
            return false;
274
        }
275
276
        return $this->getPrimaryKey() === $obj->getPrimaryKey();
277
    }
278
279
    /**
280
     * Get the associative array of the virtual columns in this object
281
     *
282
     * @return array
283
     */
284
    public function getVirtualColumns()
285
    {
286
        return $this->virtualColumns;
287
    }
288
289
    /**
290
     * Checks the existence of a virtual column in this object
291
     *
292
     * @param  string  $name The virtual column name
293
     * @return boolean
294
     */
295
    public function hasVirtualColumn($name)
296
    {
297
        return array_key_exists($name, $this->virtualColumns);
298
    }
299
300
    /**
301
     * Get the value of a virtual column in this object
302
     *
303
     * @param  string $name The virtual column name
304
     * @return mixed
305
     *
306
     * @throws PropelException
307
     */
308 View Code Duplication
    public function getVirtualColumn($name)
309
    {
310
        if (!$this->hasVirtualColumn($name)) {
311
            throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name));
312
        }
313
314
        return $this->virtualColumns[$name];
315
    }
316
317
    /**
318
     * Set the value of a virtual column in this object
319
     *
320
     * @param string $name  The virtual column name
321
     * @param mixed  $value The value to give to the virtual column
322
     *
323
     * @return $this|Banners The current object, for fluid interface
324
     */
325
    public function setVirtualColumn($name, $value)
326
    {
327
        $this->virtualColumns[$name] = $value;
328
329
        return $this;
330
    }
331
332
    /**
333
     * Logs a message using Propel::log().
334
     *
335
     * @param  string  $msg
336
     * @param  int     $priority One of the Propel::LOG_* logging levels
337
     * @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...
338
     */
339
    protected function log($msg, $priority = Propel::LOG_INFO)
340
    {
341
        return Propel::log(get_class($this) . ': ' . $msg, $priority);
342
    }
343
344
    /**
345
     * Export the current object properties to a string, using a given parser format
346
     * <code>
347
     * $book = BookQuery::create()->findPk(9012);
348
     * echo $book->exportTo('JSON');
349
     *  => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
350
     * </code>
351
     *
352
     * @param  mixed   $parser                 A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
353
     * @param  boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
354
     * @return string  The exported data
355
     */
356 View Code Duplication
    public function exportTo($parser, $includeLazyLoadColumns = true)
357
    {
358
        if (!$parser instanceof AbstractParser) {
359
            $parser = AbstractParser::getParser($parser);
360
        }
361
362
        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...
363
    }
364
365
    /**
366
     * Clean up internal collections prior to serializing
367
     * Avoids recursive loops that turn into segmentation faults when serializing
368
     */
369 View Code Duplication
    public function __sleep()
370
    {
371
        $this->clearAllReferences();
372
373
        $cls = new \ReflectionClass($this);
374
        $propertyNames = [];
375
        $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC));
376
377
        foreach($serializableProperties as $property) {
378
            $propertyNames[] = $property->getName();
379
        }
380
381
        return $propertyNames;
382
    }
383
384
    /**
385
     * Get the [id] column value.
386
     *
387
     * @return int
388
     */
389
    public function getId()
390
    {
391
        return $this->id;
392
    }
393
394
    /**
395
     * Get the [place] column value.
396
     *
397
     * @return string
398
     */
399
    public function getPlace()
400
    {
401
        return $this->place;
402
    }
403
404
    /**
405
     * Get the [width] column value.
406
     *
407
     * @return int
408
     */
409
    public function getWidth()
410
    {
411
        return $this->width;
412
    }
413
414
    /**
415
     * Get the [height] column value.
416
     *
417
     * @return int
418
     */
419
    public function getHeight()
420
    {
421
        return $this->height;
422
    }
423
424
    /**
425
     * Get the [effects] column value.
426
     *
427
     * @return string
428
     */
429
    public function getEffects()
430
    {
431
        return $this->effects;
432
    }
433
434
    /**
435
     * Get the [page_type] column value.
436
     *
437
     * @return string
438
     */
439
    public function getPageType()
440
    {
441
        return $this->page_type;
442
    }
443
444
    /**
445
     * Set the value of [id] column.
446
     *
447
     * @param int $v new value
448
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
449
     */
450 View Code Duplication
    public function setId($v)
451
    {
452
        if ($v !== null) {
453
            $v = (int) $v;
454
        }
455
456
        if ($this->id !== $v) {
457
            $this->id = $v;
458
            $this->modifiedColumns[BannersTableMap::COL_ID] = true;
459
        }
460
461
        return $this;
462
    } // setId()
463
464
    /**
465
     * Set the value of [place] column.
466
     *
467
     * @param string $v new value
468
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
469
     */
470 View Code Duplication
    public function setPlace($v)
471
    {
472
        if ($v !== null) {
473
            $v = (string) $v;
474
        }
475
476
        if ($this->place !== $v) {
477
            $this->place = $v;
478
            $this->modifiedColumns[BannersTableMap::COL_PLACE] = true;
479
        }
480
481
        return $this;
482
    } // setPlace()
483
484
    /**
485
     * Set the value of [width] column.
486
     *
487
     * @param int $v new value
488
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
489
     */
490 View Code Duplication
    public function setWidth($v)
491
    {
492
        if ($v !== null) {
493
            $v = (int) $v;
494
        }
495
496
        if ($this->width !== $v) {
497
            $this->width = $v;
498
            $this->modifiedColumns[BannersTableMap::COL_WIDTH] = true;
499
        }
500
501
        return $this;
502
    } // setWidth()
503
504
    /**
505
     * Set the value of [height] column.
506
     *
507
     * @param int $v new value
508
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
509
     */
510 View Code Duplication
    public function setHeight($v)
511
    {
512
        if ($v !== null) {
513
            $v = (int) $v;
514
        }
515
516
        if ($this->height !== $v) {
517
            $this->height = $v;
518
            $this->modifiedColumns[BannersTableMap::COL_HEIGHT] = true;
519
        }
520
521
        return $this;
522
    } // setHeight()
523
524
    /**
525
     * Set the value of [effects] column.
526
     *
527
     * @param string $v new value
528
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
529
     */
530 View Code Duplication
    public function setEffects($v)
531
    {
532
        if ($v !== null) {
533
            $v = (string) $v;
534
        }
535
536
        if ($this->effects !== $v) {
537
            $this->effects = $v;
538
            $this->modifiedColumns[BannersTableMap::COL_EFFECTS] = true;
539
        }
540
541
        return $this;
542
    } // setEffects()
543
544
    /**
545
     * Set the value of [page_type] column.
546
     *
547
     * @param string $v new value
548
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
549
     */
550 View Code Duplication
    public function setPageType($v)
551
    {
552
        if ($v !== null) {
553
            $v = (string) $v;
554
        }
555
556
        if ($this->page_type !== $v) {
557
            $this->page_type = $v;
558
            $this->modifiedColumns[BannersTableMap::COL_PAGE_TYPE] = true;
559
        }
560
561
        return $this;
562
    } // setPageType()
563
564
    /**
565
     * Indicates whether the columns in this object are only set to default values.
566
     *
567
     * This method can be used in conjunction with isModified() to indicate whether an object is both
568
     * modified _and_ has some values set which are non-default.
569
     *
570
     * @return boolean Whether the columns in this object are only been set with default values.
571
     */
572
    public function hasOnlyDefaultValues()
573
    {
574
        // otherwise, everything was equal, so return TRUE
575
        return true;
576
    } // hasOnlyDefaultValues()
577
578
    /**
579
     * Hydrates (populates) the object variables with values from the database resultset.
580
     *
581
     * An offset (0-based "start column") is specified so that objects can be hydrated
582
     * with a subset of the columns in the resultset rows.  This is needed, for example,
583
     * for results of JOIN queries where the resultset row includes columns from two or
584
     * more tables.
585
     *
586
     * @param array   $row       The row returned by DataFetcher->fetch().
587
     * @param int     $startcol  0-based offset column which indicates which restultset column to start with.
588
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
589
     * @param string  $indexType The index type of $row. Mostly DataFetcher->getIndexType().
590
                                  One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
591
     *                            TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
592
     *
593
     * @return int             next starting column
594
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
595
     */
596 View Code Duplication
    public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM)
597
    {
598
        try {
599
600
            $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : BannersTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
601
            $this->id = (null !== $col) ? (int) $col : null;
602
603
            $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : BannersTableMap::translateFieldName('Place', TableMap::TYPE_PHPNAME, $indexType)];
604
            $this->place = (null !== $col) ? (string) $col : null;
605
606
            $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : BannersTableMap::translateFieldName('Width', TableMap::TYPE_PHPNAME, $indexType)];
607
            $this->width = (null !== $col) ? (int) $col : null;
608
609
            $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : BannersTableMap::translateFieldName('Height', TableMap::TYPE_PHPNAME, $indexType)];
610
            $this->height = (null !== $col) ? (int) $col : null;
611
612
            $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : BannersTableMap::translateFieldName('Effects', TableMap::TYPE_PHPNAME, $indexType)];
613
            $this->effects = (null !== $col) ? (string) $col : null;
614
615
            $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : BannersTableMap::translateFieldName('PageType', TableMap::TYPE_PHPNAME, $indexType)];
616
            $this->page_type = (null !== $col) ? (string) $col : null;
617
            $this->resetModified();
618
619
            $this->setNew(false);
620
621
            if ($rehydrate) {
622
                $this->ensureConsistency();
623
            }
624
625
            return $startcol + 6; // 6 = BannersTableMap::NUM_HYDRATE_COLUMNS.
626
627
        } catch (Exception $e) {
628
            throw new PropelException(sprintf('Error populating %s object', '\\xbanners\\models\\Banners'), 0, $e);
629
        }
630
    }
631
632
    /**
633
     * Checks and repairs the internal consistency of the object.
634
     *
635
     * This method is executed after an already-instantiated object is re-hydrated
636
     * from the database.  It exists to check any foreign keys to make sure that
637
     * the objects related to the current object are correct based on foreign key.
638
     *
639
     * You can override this method in the stub class, but you should always invoke
640
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
641
     * in case your model changes.
642
     *
643
     * @throws PropelException
644
     */
645
    public function ensureConsistency()
646
    {
647
    } // ensureConsistency
648
649
    /**
650
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
651
     *
652
     * This will only work if the object has been saved and has a valid primary key set.
653
     *
654
     * @param      boolean $deep (optional) Whether to also de-associated any related objects.
655
     * @param      ConnectionInterface $con (optional) The ConnectionInterface connection to use.
656
     * @return void
657
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
658
     */
659 View Code Duplication
    public function reload($deep = false, ConnectionInterface $con = null)
660
    {
661
        if ($this->isDeleted()) {
662
            throw new PropelException("Cannot reload a deleted object.");
663
        }
664
665
        if ($this->isNew()) {
666
            throw new PropelException("Cannot reload an unsaved object.");
667
        }
668
669
        if ($con === null) {
670
            $con = Propel::getServiceContainer()->getReadConnection(BannersTableMap::DATABASE_NAME);
671
        }
672
673
        // We don't need to alter the object instance pool; we're just modifying this instance
674
        // already in the pool.
675
676
        $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, core\models\Base\RouteQuery, core\models\RouteQuery, 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...
677
        $row = $dataFetcher->fetch();
678
        $dataFetcher->close();
679
        if (!$row) {
680
            throw new PropelException('Cannot find matching row in the database to reload object values.');
681
        }
682
        $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate
683
684
        if ($deep) {  // also de-associate any related objects?
685
686
            $this->collBannerImages = null;
687
688
            $this->collBannersI18ns = null;
689
690
        } // if (deep)
691
    }
692
693
    /**
694
     * Removes this object from datastore and sets delete attribute.
695
     *
696
     * @param      ConnectionInterface $con
697
     * @return void
698
     * @throws PropelException
699
     * @see Banners::setDeleted()
700
     * @see Banners::isDeleted()
701
     */
702 View Code Duplication
    public function delete(ConnectionInterface $con = null)
703
    {
704
        if ($this->isDeleted()) {
705
            throw new PropelException("This object has already been deleted.");
706
        }
707
708
        if ($con === null) {
709
            $con = Propel::getServiceContainer()->getWriteConnection(BannersTableMap::DATABASE_NAME);
710
        }
711
712
        $con->transaction(function () use ($con) {
713
            $deleteQuery = ChildBannersQuery::create()
714
                ->filterByPrimaryKey($this->getPrimaryKey());
715
            $ret = $this->preDelete($con);
716
            if ($ret) {
717
                $deleteQuery->delete($con);
718
                $this->postDelete($con);
719
                $this->setDeleted(true);
720
            }
721
        });
722
    }
723
724
    /**
725
     * Persists this object to the database.
726
     *
727
     * If the object is new, it inserts it; otherwise an update is performed.
728
     * All modified related objects will also be persisted in the doSave()
729
     * method.  This method wraps all precipitate database operations in a
730
     * single transaction.
731
     *
732
     * @param      ConnectionInterface $con
733
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
734
     * @throws PropelException
735
     * @see doSave()
736
     */
737 View Code Duplication
    public function save(ConnectionInterface $con = null)
738
    {
739
        if ($this->isDeleted()) {
740
            throw new PropelException("You cannot save an object that has been deleted.");
741
        }
742
743
        if ($this->alreadyInSave) {
744
            return 0;
745
        }
746
747
        if ($con === null) {
748
            $con = Propel::getServiceContainer()->getWriteConnection(BannersTableMap::DATABASE_NAME);
749
        }
750
751
        return $con->transaction(function () use ($con) {
752
            $ret = $this->preSave($con);
753
            $isInsert = $this->isNew();
754
            if ($isInsert) {
755
                $ret = $ret && $this->preInsert($con);
756
            } else {
757
                $ret = $ret && $this->preUpdate($con);
758
            }
759
            if ($ret) {
760
                $affectedRows = $this->doSave($con);
761
                if ($isInsert) {
762
                    $this->postInsert($con);
763
                } else {
764
                    $this->postUpdate($con);
765
                }
766
                $this->postSave($con);
767
                BannersTableMap::addInstanceToPool($this);
768
            } else {
769
                $affectedRows = 0;
770
            }
771
772
            return $affectedRows;
773
        });
774
    }
775
776
    /**
777
     * Performs the work of inserting or updating the row in the database.
778
     *
779
     * If the object is new, it inserts it; otherwise an update is performed.
780
     * All related objects are also updated in this method.
781
     *
782
     * @param      ConnectionInterface $con
783
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
784
     * @throws PropelException
785
     * @see save()
786
     */
787 View Code Duplication
    protected function doSave(ConnectionInterface $con)
788
    {
789
        $affectedRows = 0; // initialize var to track total num of affected rows
790
        if (!$this->alreadyInSave) {
791
            $this->alreadyInSave = true;
792
793
            if ($this->isNew() || $this->isModified()) {
794
                // persist changes
795
                if ($this->isNew()) {
796
                    $this->doInsert($con);
797
                    $affectedRows += 1;
798
                } else {
799
                    $affectedRows += $this->doUpdate($con);
800
                }
801
                $this->resetModified();
802
            }
803
804
            if ($this->bannerImagesScheduledForDeletion !== null) {
805
                if (!$this->bannerImagesScheduledForDeletion->isEmpty()) {
806
                    \xbanners\models\BannerImageQuery::create()
807
                        ->filterByPrimaryKeys($this->bannerImagesScheduledForDeletion->getPrimaryKeys(false))
808
                        ->delete($con);
809
                    $this->bannerImagesScheduledForDeletion = null;
810
                }
811
            }
812
813
            if ($this->collBannerImages !== null) {
814
                foreach ($this->collBannerImages as $referrerFK) {
815
                    if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
816
                        $affectedRows += $referrerFK->save($con);
817
                    }
818
                }
819
            }
820
821
            if ($this->bannersI18nsScheduledForDeletion !== null) {
822
                if (!$this->bannersI18nsScheduledForDeletion->isEmpty()) {
823
                    \xbanners\models\BannersI18nQuery::create()
824
                        ->filterByPrimaryKeys($this->bannersI18nsScheduledForDeletion->getPrimaryKeys(false))
825
                        ->delete($con);
826
                    $this->bannersI18nsScheduledForDeletion = null;
827
                }
828
            }
829
830
            if ($this->collBannersI18ns !== null) {
831
                foreach ($this->collBannersI18ns as $referrerFK) {
832
                    if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
833
                        $affectedRows += $referrerFK->save($con);
834
                    }
835
                }
836
            }
837
838
            $this->alreadyInSave = false;
839
840
        }
841
842
        return $affectedRows;
843
    } // doSave()
844
845
    /**
846
     * Insert the row in the database.
847
     *
848
     * @param      ConnectionInterface $con
849
     *
850
     * @throws PropelException
851
     * @see doSave()
852
     */
853
    protected function doInsert(ConnectionInterface $con)
854
    {
855
        $modifiedColumns = array();
856
        $index = 0;
857
858
        $this->modifiedColumns[BannersTableMap::COL_ID] = true;
859
        if (null !== $this->id) {
860
            throw new PropelException('Cannot insert a value for auto-increment primary key (' . BannersTableMap::COL_ID . ')');
861
        }
862
863
         // check the columns in natural order for more readable SQL queries
864
        if ($this->isColumnModified(BannersTableMap::COL_ID)) {
865
            $modifiedColumns[':p' . $index++]  = 'id';
866
        }
867
        if ($this->isColumnModified(BannersTableMap::COL_PLACE)) {
868
            $modifiedColumns[':p' . $index++]  = 'place';
869
        }
870
        if ($this->isColumnModified(BannersTableMap::COL_WIDTH)) {
871
            $modifiedColumns[':p' . $index++]  = 'width';
872
        }
873
        if ($this->isColumnModified(BannersTableMap::COL_HEIGHT)) {
874
            $modifiedColumns[':p' . $index++]  = 'height';
875
        }
876
        if ($this->isColumnModified(BannersTableMap::COL_EFFECTS)) {
877
            $modifiedColumns[':p' . $index++]  = 'effects';
878
        }
879
        if ($this->isColumnModified(BannersTableMap::COL_PAGE_TYPE)) {
880
            $modifiedColumns[':p' . $index++]  = 'page_type';
881
        }
882
883
        $sql = sprintf(
884
            'INSERT INTO banners (%s) VALUES (%s)',
885
            implode(', ', $modifiedColumns),
886
            implode(', ', array_keys($modifiedColumns))
887
        );
888
889
        try {
890
            $stmt = $con->prepare($sql);
891
            foreach ($modifiedColumns as $identifier => $columnName) {
892
                switch ($columnName) {
893
                    case 'id':
894
                        $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
895
                        break;
896
                    case 'place':
897
                        $stmt->bindValue($identifier, $this->place, PDO::PARAM_STR);
898
                        break;
899
                    case 'width':
900
                        $stmt->bindValue($identifier, $this->width, PDO::PARAM_INT);
901
                        break;
902
                    case 'height':
903
                        $stmt->bindValue($identifier, $this->height, PDO::PARAM_INT);
904
                        break;
905
                    case 'effects':
906
                        $stmt->bindValue($identifier, $this->effects, PDO::PARAM_STR);
907
                        break;
908
                    case 'page_type':
909
                        $stmt->bindValue($identifier, $this->page_type, PDO::PARAM_STR);
910
                        break;
911
                }
912
            }
913
            $stmt->execute();
914
        } catch (Exception $e) {
915
            Propel::log($e->getMessage(), Propel::LOG_ERR);
916
            throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
917
        }
918
919
        try {
920
            $pk = $con->lastInsertId();
921
        } catch (Exception $e) {
922
            throw new PropelException('Unable to get autoincrement id.', 0, $e);
923
        }
924
        $this->setId($pk);
925
926
        $this->setNew(false);
927
    }
928
929
    /**
930
     * Update the row in the database.
931
     *
932
     * @param      ConnectionInterface $con
933
     *
934
     * @return Integer Number of updated rows
935
     * @see doSave()
936
     */
937
    protected function doUpdate(ConnectionInterface $con)
938
    {
939
        $selectCriteria = $this->buildPkeyCriteria();
940
        $valuesCriteria = $this->buildCriteria();
941
942
        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...
943
    }
944
945
    /**
946
     * Retrieves a field from the object by name passed in as a string.
947
     *
948
     * @param      string $name name
949
     * @param      string $type The type of fieldname the $name is of:
950
     *                     one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
951
     *                     TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
952
     *                     Defaults to TableMap::TYPE_PHPNAME.
953
     * @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...
954
     */
955 View Code Duplication
    public function getByName($name, $type = TableMap::TYPE_PHPNAME)
956
    {
957
        $pos = BannersTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
958
        $field = $this->getByPosition($pos);
959
960
        return $field;
961
    }
962
963
    /**
964
     * Retrieves a field from the object by Position as specified in the xml schema.
965
     * Zero-based.
966
     *
967
     * @param      int $pos position in xml schema
968
     * @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...
969
     */
970
    public function getByPosition($pos)
971
    {
972
        switch ($pos) {
973
            case 0:
974
                return $this->getId();
975
                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...
976
            case 1:
977
                return $this->getPlace();
978
                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...
979
            case 2:
980
                return $this->getWidth();
981
                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...
982
            case 3:
983
                return $this->getHeight();
984
                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...
985
            case 4:
986
                return $this->getEffects();
987
                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...
988
            case 5:
989
                return $this->getPageType();
990
                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...
991
            default:
992
                return null;
993
                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...
994
        } // switch()
995
    }
996
997
    /**
998
     * Exports the object as an array.
999
     *
1000
     * You can specify the key type of the array by passing one of the class
1001
     * type constants.
1002
     *
1003
     * @param     string  $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1004
     *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1005
     *                    Defaults to TableMap::TYPE_PHPNAME.
1006
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
1007
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
1008
     * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
1009
     *
1010
     * @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...
1011
     */
1012 View Code Duplication
    public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
1013
    {
1014
1015
        if (isset($alreadyDumpedObjects['Banners'][$this->hashCode()])) {
1016
            return '*RECURSION*';
1017
        }
1018
        $alreadyDumpedObjects['Banners'][$this->hashCode()] = true;
1019
        $keys = BannersTableMap::getFieldNames($keyType);
1020
        $result = array(
1021
            $keys[0] => $this->getId(),
1022
            $keys[1] => $this->getPlace(),
1023
            $keys[2] => $this->getWidth(),
1024
            $keys[3] => $this->getHeight(),
1025
            $keys[4] => $this->getEffects(),
1026
            $keys[5] => $this->getPageType(),
1027
        );
1028
        $virtualColumns = $this->virtualColumns;
1029
        foreach ($virtualColumns as $key => $virtualColumn) {
1030
            $result[$key] = $virtualColumn;
1031
        }
1032
1033
        if ($includeForeignObjects) {
1034
            if (null !== $this->collBannerImages) {
1035
1036
                switch ($keyType) {
1037
                    case TableMap::TYPE_CAMELNAME:
1038
                        $key = 'bannerImages';
1039
                        break;
1040
                    case TableMap::TYPE_FIELDNAME:
1041
                        $key = 'banner_images';
1042
                        break;
1043
                    default:
1044
                        $key = 'BannerImages';
1045
                }
1046
1047
                $result[$key] = $this->collBannerImages->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
1048
            }
1049
            if (null !== $this->collBannersI18ns) {
1050
1051
                switch ($keyType) {
1052
                    case TableMap::TYPE_CAMELNAME:
1053
                        $key = 'bannersI18ns';
1054
                        break;
1055
                    case TableMap::TYPE_FIELDNAME:
1056
                        $key = 'banners_i18ns';
1057
                        break;
1058
                    default:
1059
                        $key = 'BannersI18ns';
1060
                }
1061
1062
                $result[$key] = $this->collBannersI18ns->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
1063
            }
1064
        }
1065
1066
        return $result;
1067
    }
1068
1069
    /**
1070
     * Sets a field from the object by name passed in as a string.
1071
     *
1072
     * @param  string $name
1073
     * @param  mixed  $value field value
1074
     * @param  string $type The type of fieldname the $name is of:
1075
     *                one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
1076
     *                TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1077
     *                Defaults to TableMap::TYPE_PHPNAME.
1078
     * @return $this|\xbanners\models\Banners
1079
     */
1080
    public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME)
1081
    {
1082
        $pos = BannersTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
1083
1084
        return $this->setByPosition($pos, $value);
1085
    }
1086
1087
    /**
1088
     * Sets a field from the object by Position as specified in the xml schema.
1089
     * Zero-based.
1090
     *
1091
     * @param  int $pos position in xml schema
1092
     * @param  mixed $value field value
1093
     * @return $this|\xbanners\models\Banners
1094
     */
1095
    public function setByPosition($pos, $value)
1096
    {
1097
        switch ($pos) {
1098
            case 0:
1099
                $this->setId($value);
1100
                break;
1101
            case 1:
1102
                $this->setPlace($value);
1103
                break;
1104
            case 2:
1105
                $this->setWidth($value);
1106
                break;
1107
            case 3:
1108
                $this->setHeight($value);
1109
                break;
1110
            case 4:
1111
                $this->setEffects($value);
1112
                break;
1113
            case 5:
1114
                $this->setPageType($value);
1115
                break;
1116
        } // switch()
1117
1118
        return $this;
1119
    }
1120
1121
    /**
1122
     * Populates the object using an array.
1123
     *
1124
     * This is particularly useful when populating an object from one of the
1125
     * request arrays (e.g. $_POST).  This method goes through the column
1126
     * names, checking to see whether a matching key exists in populated
1127
     * array. If so the setByName() method is called for that column.
1128
     *
1129
     * You can specify the key type of the array by additionally passing one
1130
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1131
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1132
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1133
     *
1134
     * @param      array  $arr     An array to populate the object from.
1135
     * @param      string $keyType The type of keys the array uses.
1136
     * @return void
1137
     */
1138 View Code Duplication
    public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME)
1139
    {
1140
        $keys = BannersTableMap::getFieldNames($keyType);
1141
1142
        if (array_key_exists($keys[0], $arr)) {
1143
            $this->setId($arr[$keys[0]]);
1144
        }
1145
        if (array_key_exists($keys[1], $arr)) {
1146
            $this->setPlace($arr[$keys[1]]);
1147
        }
1148
        if (array_key_exists($keys[2], $arr)) {
1149
            $this->setWidth($arr[$keys[2]]);
1150
        }
1151
        if (array_key_exists($keys[3], $arr)) {
1152
            $this->setHeight($arr[$keys[3]]);
1153
        }
1154
        if (array_key_exists($keys[4], $arr)) {
1155
            $this->setEffects($arr[$keys[4]]);
1156
        }
1157
        if (array_key_exists($keys[5], $arr)) {
1158
            $this->setPageType($arr[$keys[5]]);
1159
        }
1160
    }
1161
1162
     /**
1163
     * Populate the current object from a string, using a given parser format
1164
     * <code>
1165
     * $book = new Book();
1166
     * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
1167
     * </code>
1168
     *
1169
     * You can specify the key type of the array by additionally passing one
1170
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1171
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1172
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1173
     *
1174
     * @param mixed $parser A AbstractParser instance,
1175
     *                       or a format name ('XML', 'YAML', 'JSON', 'CSV')
1176
     * @param string $data The source data to import from
1177
     * @param string $keyType The type of keys the array uses.
1178
     *
1179
     * @return $this|\xbanners\models\Banners The current object, for fluid interface
1180
     */
1181 View Code Duplication
    public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME)
1182
    {
1183
        if (!$parser instanceof AbstractParser) {
1184
            $parser = AbstractParser::getParser($parser);
1185
        }
1186
1187
        $this->fromArray($parser->toArray($data), $keyType);
1188
1189
        return $this;
1190
    }
1191
1192
    /**
1193
     * Build a Criteria object containing the values of all modified columns in this object.
1194
     *
1195
     * @return Criteria The Criteria object containing all modified values.
1196
     */
1197
    public function buildCriteria()
1198
    {
1199
        $criteria = new Criteria(BannersTableMap::DATABASE_NAME);
1200
1201
        if ($this->isColumnModified(BannersTableMap::COL_ID)) {
1202
            $criteria->add(BannersTableMap::COL_ID, $this->id);
1203
        }
1204
        if ($this->isColumnModified(BannersTableMap::COL_PLACE)) {
1205
            $criteria->add(BannersTableMap::COL_PLACE, $this->place);
1206
        }
1207
        if ($this->isColumnModified(BannersTableMap::COL_WIDTH)) {
1208
            $criteria->add(BannersTableMap::COL_WIDTH, $this->width);
1209
        }
1210
        if ($this->isColumnModified(BannersTableMap::COL_HEIGHT)) {
1211
            $criteria->add(BannersTableMap::COL_HEIGHT, $this->height);
1212
        }
1213
        if ($this->isColumnModified(BannersTableMap::COL_EFFECTS)) {
1214
            $criteria->add(BannersTableMap::COL_EFFECTS, $this->effects);
1215
        }
1216
        if ($this->isColumnModified(BannersTableMap::COL_PAGE_TYPE)) {
1217
            $criteria->add(BannersTableMap::COL_PAGE_TYPE, $this->page_type);
1218
        }
1219
1220
        return $criteria;
1221
    }
1222
1223
    /**
1224
     * Builds a Criteria object containing the primary key for this object.
1225
     *
1226
     * Unlike buildCriteria() this method includes the primary key values regardless
1227
     * of whether or not they have been modified.
1228
     *
1229
     * @throws LogicException if no primary key is defined
1230
     *
1231
     * @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...
1232
     */
1233
    public function buildPkeyCriteria()
1234
    {
1235
        $criteria = ChildBannersQuery::create();
1236
        $criteria->add(BannersTableMap::COL_ID, $this->id);
1237
1238
        return $criteria;
1239
    }
1240
1241
    /**
1242
     * If the primary key is not null, return the hashcode of the
1243
     * primary key. Otherwise, return the hash code of the object.
1244
     *
1245
     * @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...
1246
     */
1247 View Code Duplication
    public function hashCode()
1248
    {
1249
        $validPk = null !== $this->getId();
1250
1251
        $validPrimaryKeyFKs = 0;
1252
        $primaryKeyFKs = [];
1253
1254
        if ($validPk) {
1255
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
1256
        } elseif ($validPrimaryKeyFKs) {
1257
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
1258
        }
1259
1260
        return spl_object_hash($this);
1261
    }
1262
1263
    /**
1264
     * Returns the primary key for this object (row).
1265
     * @return int
1266
     */
1267
    public function getPrimaryKey()
1268
    {
1269
        return $this->getId();
1270
    }
1271
1272
    /**
1273
     * Generic method to set the primary key (id column).
1274
     *
1275
     * @param       int $key Primary key.
1276
     * @return void
1277
     */
1278
    public function setPrimaryKey($key)
1279
    {
1280
        $this->setId($key);
1281
    }
1282
1283
    /**
1284
     * Returns true if the primary key for this object is null.
1285
     * @return boolean
1286
     */
1287
    public function isPrimaryKeyNull()
1288
    {
1289
        return null === $this->getId();
1290
    }
1291
1292
    /**
1293
     * Sets contents of passed object to values from current object.
1294
     *
1295
     * If desired, this method can also make copies of all associated (fkey referrers)
1296
     * objects.
1297
     *
1298
     * @param      object $copyObj An object of \xbanners\models\Banners (or compatible) type.
1299
     * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1300
     * @param      boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1301
     * @throws PropelException
1302
     */
1303
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1304
    {
1305
        $copyObj->setPlace($this->getPlace());
1306
        $copyObj->setWidth($this->getWidth());
1307
        $copyObj->setHeight($this->getHeight());
1308
        $copyObj->setEffects($this->getEffects());
1309
        $copyObj->setPageType($this->getPageType());
1310
1311
        if ($deepCopy) {
1312
            // important: temporarily setNew(false) because this affects the behavior of
1313
            // the getter/setter methods for fkey referrer objects.
1314
            $copyObj->setNew(false);
1315
1316
            foreach ($this->getBannerImages() as $relObj) {
1317
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
1318
                    $copyObj->addBannerImage($relObj->copy($deepCopy));
1319
                }
1320
            }
1321
1322
            foreach ($this->getBannersI18ns() as $relObj) {
1323
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
1324
                    $copyObj->addBannersI18n($relObj->copy($deepCopy));
1325
                }
1326
            }
1327
1328
        } // if ($deepCopy)
1329
1330
        if ($makeNew) {
1331
            $copyObj->setNew(true);
1332
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1333
        }
1334
    }
1335
1336
    /**
1337
     * Makes a copy of this object that will be inserted as a new row in table when saved.
1338
     * It creates a new object filling in the simple attributes, but skipping any primary
1339
     * keys that are defined for the table.
1340
     *
1341
     * If desired, this method can also make copies of all associated (fkey referrers)
1342
     * objects.
1343
     *
1344
     * @param  boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1345
     * @return \xbanners\models\Banners Clone of current object.
1346
     * @throws PropelException
1347
     */
1348 View Code Duplication
    public function copy($deepCopy = false)
1349
    {
1350
        // we use get_class(), because this might be a subclass
1351
        $clazz = get_class($this);
1352
        $copyObj = new $clazz();
1353
        $this->copyInto($copyObj, $deepCopy);
1354
1355
        return $copyObj;
1356
    }
1357
1358
1359
    /**
1360
     * Initializes a collection based on the name of a relation.
1361
     * Avoids crafting an 'init[$relationName]s' method name
1362
     * that wouldn't work when StandardEnglishPluralizer is used.
1363
     *
1364
     * @param      string $relationName The name of the relation to initialize
1365
     * @return void
1366
     */
1367
    public function initRelation($relationName)
1368
    {
1369
        if ('BannerImage' == $relationName) {
1370
            return $this->initBannerImages();
1371
        }
1372
        if ('BannersI18n' == $relationName) {
1373
            return $this->initBannersI18ns();
1374
        }
1375
    }
1376
1377
    /**
1378
     * Clears out the collBannerImages collection
1379
     *
1380
     * This does not modify the database; however, it will remove any associated objects, causing
1381
     * them to be refetched by subsequent calls to accessor method.
1382
     *
1383
     * @return void
1384
     * @see        addBannerImages()
1385
     */
1386
    public function clearBannerImages()
1387
    {
1388
        $this->collBannerImages = null; // important to set this to NULL since that means it is uninitialized
1389
    }
1390
1391
    /**
1392
     * Reset is the collBannerImages collection loaded partially.
1393
     */
1394
    public function resetPartialBannerImages($v = true)
1395
    {
1396
        $this->collBannerImagesPartial = $v;
1397
    }
1398
1399
    /**
1400
     * Initializes the collBannerImages collection.
1401
     *
1402
     * By default this just sets the collBannerImages collection to an empty array (like clearcollBannerImages());
1403
     * however, you may wish to override this method in your stub class to provide setting appropriate
1404
     * to your application -- for example, setting the initial array to the values stored in database.
1405
     *
1406
     * @param      boolean $overrideExisting If set to true, the method call initializes
1407
     *                                        the collection even if it is not empty
1408
     *
1409
     * @return void
1410
     */
1411 View Code Duplication
    public function initBannerImages($overrideExisting = true)
1412
    {
1413
        if (null !== $this->collBannerImages && !$overrideExisting) {
1414
            return;
1415
        }
1416
1417
        $collectionClassName = BannerImageTableMap::getTableMap()->getCollectionClassName();
1418
1419
        $this->collBannerImages = new $collectionClassName;
1420
        $this->collBannerImages->setModel('\xbanners\models\BannerImage');
1421
    }
1422
1423
    /**
1424
     * Gets an array of ChildBannerImage objects which contain a foreign key that references this object.
1425
     *
1426
     * If the $criteria is not null, it is used to always fetch the results from the database.
1427
     * Otherwise the results are fetched from the database the first time, then cached.
1428
     * Next time the same method is called without $criteria, the cached collection is returned.
1429
     * If this ChildBanners is new, it will return
1430
     * an empty collection or the current collection; the criteria is ignored on a new object.
1431
     *
1432
     * @param      Criteria $criteria optional Criteria object to narrow the query
1433
     * @param      ConnectionInterface $con optional connection object
1434
     * @return ObjectCollection|ChildBannerImage[] List of ChildBannerImage objects
1435
     * @throws PropelException
1436
     */
1437 View Code Duplication
    public function getBannerImages(Criteria $criteria = null, ConnectionInterface $con = null)
1438
    {
1439
        $partial = $this->collBannerImagesPartial && !$this->isNew();
1440
        if (null === $this->collBannerImages || null !== $criteria  || $partial) {
1441
            if ($this->isNew() && null === $this->collBannerImages) {
1442
                // return empty collection
1443
                $this->initBannerImages();
1444
            } else {
1445
                $collBannerImages = ChildBannerImageQuery::create(null, $criteria)
1446
                    ->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...
1447
                    ->find($con);
0 ignored issues
show
Bug introduced by
It seems like $con defined by parameter $con on line 1437 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...
1448
1449
                if (null !== $criteria) {
1450
                    if (false !== $this->collBannerImagesPartial && count($collBannerImages)) {
1451
                        $this->initBannerImages(false);
1452
1453
                        foreach ($collBannerImages as $obj) {
1454
                            if (false == $this->collBannerImages->contains($obj)) {
1455
                                $this->collBannerImages->append($obj);
1456
                            }
1457
                        }
1458
1459
                        $this->collBannerImagesPartial = true;
1460
                    }
1461
1462
                    return $collBannerImages;
1463
                }
1464
1465
                if ($partial && $this->collBannerImages) {
1466
                    foreach ($this->collBannerImages as $obj) {
1467
                        if ($obj->isNew()) {
1468
                            $collBannerImages[] = $obj;
1469
                        }
1470
                    }
1471
                }
1472
1473
                $this->collBannerImages = $collBannerImages;
1474
                $this->collBannerImagesPartial = false;
1475
            }
1476
        }
1477
1478
        return $this->collBannerImages;
1479
    }
1480
1481
    /**
1482
     * Sets a collection of ChildBannerImage objects related by a one-to-many relationship
1483
     * to the current object.
1484
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1485
     * and new objects from the given Propel collection.
1486
     *
1487
     * @param      Collection $bannerImages A Propel collection.
1488
     * @param      ConnectionInterface $con Optional connection object
1489
     * @return $this|ChildBanners The current object (for fluent API support)
1490
     */
1491 View Code Duplication
    public function setBannerImages(Collection $bannerImages, ConnectionInterface $con = null)
1492
    {
1493
        /** @var ChildBannerImage[] $bannerImagesToDelete */
1494
        $bannerImagesToDelete = $this->getBannerImages(new Criteria(), $con)->diff($bannerImages);
1495
1496
1497
        $this->bannerImagesScheduledForDeletion = $bannerImagesToDelete;
1498
1499
        foreach ($bannerImagesToDelete as $bannerImageRemoved) {
1500
            $bannerImageRemoved->setBanners(null);
1501
        }
1502
1503
        $this->collBannerImages = null;
1504
        foreach ($bannerImages as $bannerImage) {
1505
            $this->addBannerImage($bannerImage);
1506
        }
1507
1508
        $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...
1509
        $this->collBannerImagesPartial = false;
1510
1511
        return $this;
1512
    }
1513
1514
    /**
1515
     * Returns the number of related BannerImage objects.
1516
     *
1517
     * @param      Criteria $criteria
1518
     * @param      boolean $distinct
1519
     * @param      ConnectionInterface $con
1520
     * @return int             Count of related BannerImage objects.
1521
     * @throws PropelException
1522
     */
1523 View Code Duplication
    public function countBannerImages(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
1524
    {
1525
        $partial = $this->collBannerImagesPartial && !$this->isNew();
1526
        if (null === $this->collBannerImages || null !== $criteria || $partial) {
1527
            if ($this->isNew() && null === $this->collBannerImages) {
1528
                return 0;
1529
            }
1530
1531
            if ($partial && !$criteria) {
1532
                return count($this->getBannerImages());
1533
            }
1534
1535
            $query = ChildBannerImageQuery::create(null, $criteria);
1536
            if ($distinct) {
1537
                $query->distinct();
1538
            }
1539
1540
            return $query
1541
                ->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...
1542
                ->count($con);
1543
        }
1544
1545
        return count($this->collBannerImages);
1546
    }
1547
1548
    /**
1549
     * Method called to associate a ChildBannerImage object to this object
1550
     * through the ChildBannerImage foreign key attribute.
1551
     *
1552
     * @param  ChildBannerImage $l ChildBannerImage
1553
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
1554
     */
1555
    public function addBannerImage(ChildBannerImage $l)
1556
    {
1557
        if ($this->collBannerImages === null) {
1558
            $this->initBannerImages();
1559
            $this->collBannerImagesPartial = true;
1560
        }
1561
1562
        if (!$this->collBannerImages->contains($l)) {
1563
            $this->doAddBannerImage($l);
1564
1565
            if ($this->bannerImagesScheduledForDeletion and $this->bannerImagesScheduledForDeletion->contains($l)) {
1566
                $this->bannerImagesScheduledForDeletion->remove($this->bannerImagesScheduledForDeletion->search($l));
1567
            }
1568
        }
1569
1570
        return $this;
1571
    }
1572
1573
    /**
1574
     * @param ChildBannerImage $bannerImage The ChildBannerImage object to add.
1575
     */
1576
    protected function doAddBannerImage(ChildBannerImage $bannerImage)
1577
    {
1578
        $this->collBannerImages[]= $bannerImage;
1579
        $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...
1580
    }
1581
1582
    /**
1583
     * @param  ChildBannerImage $bannerImage The ChildBannerImage object to remove.
1584
     * @return $this|ChildBanners The current object (for fluent API support)
1585
     */
1586 View Code Duplication
    public function removeBannerImage(ChildBannerImage $bannerImage)
1587
    {
1588
        if ($this->getBannerImages()->contains($bannerImage)) {
1589
            $pos = $this->collBannerImages->search($bannerImage);
1590
            $this->collBannerImages->remove($pos);
1591
            if (null === $this->bannerImagesScheduledForDeletion) {
1592
                $this->bannerImagesScheduledForDeletion = clone $this->collBannerImages;
1593
                $this->bannerImagesScheduledForDeletion->clear();
1594
            }
1595
            $this->bannerImagesScheduledForDeletion[]= clone $bannerImage;
1596
            $bannerImage->setBanners(null);
1597
        }
1598
1599
        return $this;
1600
    }
1601
1602
    /**
1603
     * Clears out the collBannersI18ns collection
1604
     *
1605
     * This does not modify the database; however, it will remove any associated objects, causing
1606
     * them to be refetched by subsequent calls to accessor method.
1607
     *
1608
     * @return void
1609
     * @see        addBannersI18ns()
1610
     */
1611
    public function clearBannersI18ns()
1612
    {
1613
        $this->collBannersI18ns = null; // important to set this to NULL since that means it is uninitialized
1614
    }
1615
1616
    /**
1617
     * Reset is the collBannersI18ns collection loaded partially.
1618
     */
1619
    public function resetPartialBannersI18ns($v = true)
1620
    {
1621
        $this->collBannersI18nsPartial = $v;
1622
    }
1623
1624
    /**
1625
     * Initializes the collBannersI18ns collection.
1626
     *
1627
     * By default this just sets the collBannersI18ns collection to an empty array (like clearcollBannersI18ns());
1628
     * however, you may wish to override this method in your stub class to provide setting appropriate
1629
     * to your application -- for example, setting the initial array to the values stored in database.
1630
     *
1631
     * @param      boolean $overrideExisting If set to true, the method call initializes
1632
     *                                        the collection even if it is not empty
1633
     *
1634
     * @return void
1635
     */
1636 View Code Duplication
    public function initBannersI18ns($overrideExisting = true)
1637
    {
1638
        if (null !== $this->collBannersI18ns && !$overrideExisting) {
1639
            return;
1640
        }
1641
1642
        $collectionClassName = BannersI18nTableMap::getTableMap()->getCollectionClassName();
1643
1644
        $this->collBannersI18ns = new $collectionClassName;
1645
        $this->collBannersI18ns->setModel('\xbanners\models\BannersI18n');
1646
    }
1647
1648
    /**
1649
     * Gets an array of ChildBannersI18n objects which contain a foreign key that references this object.
1650
     *
1651
     * If the $criteria is not null, it is used to always fetch the results from the database.
1652
     * Otherwise the results are fetched from the database the first time, then cached.
1653
     * Next time the same method is called without $criteria, the cached collection is returned.
1654
     * If this ChildBanners is new, it will return
1655
     * an empty collection or the current collection; the criteria is ignored on a new object.
1656
     *
1657
     * @param      Criteria $criteria optional Criteria object to narrow the query
1658
     * @param      ConnectionInterface $con optional connection object
1659
     * @return ObjectCollection|ChildBannersI18n[] List of ChildBannersI18n objects
1660
     * @throws PropelException
1661
     */
1662 View Code Duplication
    public function getBannersI18ns(Criteria $criteria = null, ConnectionInterface $con = null)
1663
    {
1664
        $partial = $this->collBannersI18nsPartial && !$this->isNew();
1665
        if (null === $this->collBannersI18ns || null !== $criteria  || $partial) {
1666
            if ($this->isNew() && null === $this->collBannersI18ns) {
1667
                // return empty collection
1668
                $this->initBannersI18ns();
1669
            } else {
1670
                $collBannersI18ns = ChildBannersI18nQuery::create(null, $criteria)
1671
                    ->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...
1672
                    ->find($con);
0 ignored issues
show
Bug introduced by
It seems like $con defined by parameter $con on line 1662 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...
1673
1674
                if (null !== $criteria) {
1675
                    if (false !== $this->collBannersI18nsPartial && count($collBannersI18ns)) {
1676
                        $this->initBannersI18ns(false);
1677
1678
                        foreach ($collBannersI18ns as $obj) {
1679
                            if (false == $this->collBannersI18ns->contains($obj)) {
1680
                                $this->collBannersI18ns->append($obj);
1681
                            }
1682
                        }
1683
1684
                        $this->collBannersI18nsPartial = true;
1685
                    }
1686
1687
                    return $collBannersI18ns;
1688
                }
1689
1690
                if ($partial && $this->collBannersI18ns) {
1691
                    foreach ($this->collBannersI18ns as $obj) {
1692
                        if ($obj->isNew()) {
1693
                            $collBannersI18ns[] = $obj;
1694
                        }
1695
                    }
1696
                }
1697
1698
                $this->collBannersI18ns = $collBannersI18ns;
1699
                $this->collBannersI18nsPartial = false;
1700
            }
1701
        }
1702
1703
        return $this->collBannersI18ns;
1704
    }
1705
1706
    /**
1707
     * Sets a collection of ChildBannersI18n objects related by a one-to-many relationship
1708
     * to the current object.
1709
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1710
     * and new objects from the given Propel collection.
1711
     *
1712
     * @param      Collection $bannersI18ns A Propel collection.
1713
     * @param      ConnectionInterface $con Optional connection object
1714
     * @return $this|ChildBanners The current object (for fluent API support)
1715
     */
1716 View Code Duplication
    public function setBannersI18ns(Collection $bannersI18ns, ConnectionInterface $con = null)
1717
    {
1718
        /** @var ChildBannersI18n[] $bannersI18nsToDelete */
1719
        $bannersI18nsToDelete = $this->getBannersI18ns(new Criteria(), $con)->diff($bannersI18ns);
1720
1721
1722
        //since at least one column in the foreign key is at the same time a PK
1723
        //we can not just set a PK to NULL in the lines below. We have to store
1724
        //a backup of all values, so we are able to manipulate these items based on the onDelete value later.
1725
        $this->bannersI18nsScheduledForDeletion = clone $bannersI18nsToDelete;
1726
1727
        foreach ($bannersI18nsToDelete as $bannersI18nRemoved) {
1728
            $bannersI18nRemoved->setBanners(null);
1729
        }
1730
1731
        $this->collBannersI18ns = null;
1732
        foreach ($bannersI18ns as $bannersI18n) {
1733
            $this->addBannersI18n($bannersI18n);
1734
        }
1735
1736
        $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...
1737
        $this->collBannersI18nsPartial = false;
1738
1739
        return $this;
1740
    }
1741
1742
    /**
1743
     * Returns the number of related BannersI18n objects.
1744
     *
1745
     * @param      Criteria $criteria
1746
     * @param      boolean $distinct
1747
     * @param      ConnectionInterface $con
1748
     * @return int             Count of related BannersI18n objects.
1749
     * @throws PropelException
1750
     */
1751 View Code Duplication
    public function countBannersI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
1752
    {
1753
        $partial = $this->collBannersI18nsPartial && !$this->isNew();
1754
        if (null === $this->collBannersI18ns || null !== $criteria || $partial) {
1755
            if ($this->isNew() && null === $this->collBannersI18ns) {
1756
                return 0;
1757
            }
1758
1759
            if ($partial && !$criteria) {
1760
                return count($this->getBannersI18ns());
1761
            }
1762
1763
            $query = ChildBannersI18nQuery::create(null, $criteria);
1764
            if ($distinct) {
1765
                $query->distinct();
1766
            }
1767
1768
            return $query
1769
                ->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...
1770
                ->count($con);
1771
        }
1772
1773
        return count($this->collBannersI18ns);
1774
    }
1775
1776
    /**
1777
     * Method called to associate a ChildBannersI18n object to this object
1778
     * through the ChildBannersI18n foreign key attribute.
1779
     *
1780
     * @param  ChildBannersI18n $l ChildBannersI18n
1781
     * @return $this|\xbanners\models\Banners The current object (for fluent API support)
1782
     */
1783 View Code Duplication
    public function addBannersI18n(ChildBannersI18n $l)
1784
    {
1785
        if ($l && $locale = $l->getLocale()) {
1786
            $this->setLocale($locale);
1787
            $this->currentTranslations[$locale] = $l;
1788
        }
1789
        if ($this->collBannersI18ns === null) {
1790
            $this->initBannersI18ns();
1791
            $this->collBannersI18nsPartial = true;
1792
        }
1793
1794
        if (!$this->collBannersI18ns->contains($l)) {
1795
            $this->doAddBannersI18n($l);
1796
1797
            if ($this->bannersI18nsScheduledForDeletion and $this->bannersI18nsScheduledForDeletion->contains($l)) {
1798
                $this->bannersI18nsScheduledForDeletion->remove($this->bannersI18nsScheduledForDeletion->search($l));
1799
            }
1800
        }
1801
1802
        return $this;
1803
    }
1804
1805
    /**
1806
     * @param ChildBannersI18n $bannersI18n The ChildBannersI18n object to add.
1807
     */
1808
    protected function doAddBannersI18n(ChildBannersI18n $bannersI18n)
1809
    {
1810
        $this->collBannersI18ns[]= $bannersI18n;
1811
        $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...
1812
    }
1813
1814
    /**
1815
     * @param  ChildBannersI18n $bannersI18n The ChildBannersI18n object to remove.
1816
     * @return $this|ChildBanners The current object (for fluent API support)
1817
     */
1818 View Code Duplication
    public function removeBannersI18n(ChildBannersI18n $bannersI18n)
1819
    {
1820
        if ($this->getBannersI18ns()->contains($bannersI18n)) {
1821
            $pos = $this->collBannersI18ns->search($bannersI18n);
1822
            $this->collBannersI18ns->remove($pos);
1823
            if (null === $this->bannersI18nsScheduledForDeletion) {
1824
                $this->bannersI18nsScheduledForDeletion = clone $this->collBannersI18ns;
1825
                $this->bannersI18nsScheduledForDeletion->clear();
1826
            }
1827
            $this->bannersI18nsScheduledForDeletion[]= clone $bannersI18n;
1828
            $bannersI18n->setBanners(null);
1829
        }
1830
1831
        return $this;
1832
    }
1833
1834
    /**
1835
     * Clears the current object, sets all attributes to their default values and removes
1836
     * outgoing references as well as back-references (from other objects to this one. Results probably in a database
1837
     * change of those foreign objects when you call `save` there).
1838
     */
1839 View Code Duplication
    public function clear()
1840
    {
1841
        $this->id = null;
1842
        $this->place = null;
1843
        $this->width = null;
1844
        $this->height = null;
1845
        $this->effects = null;
1846
        $this->page_type = null;
1847
        $this->alreadyInSave = false;
1848
        $this->clearAllReferences();
1849
        $this->resetModified();
1850
        $this->setNew(true);
1851
        $this->setDeleted(false);
1852
    }
1853
1854
    /**
1855
     * Resets all references and back-references to other model objects or collections of model objects.
1856
     *
1857
     * This method is used to reset all php object references (not the actual reference in the database).
1858
     * Necessary for object serialisation.
1859
     *
1860
     * @param      boolean $deep Whether to also clear the references on all referrer objects.
1861
     */
1862
    public function clearAllReferences($deep = false)
1863
    {
1864
        if ($deep) {
1865
            if ($this->collBannerImages) {
1866
                foreach ($this->collBannerImages as $o) {
1867
                    $o->clearAllReferences($deep);
1868
                }
1869
            }
1870
            if ($this->collBannersI18ns) {
1871
                foreach ($this->collBannersI18ns as $o) {
1872
                    $o->clearAllReferences($deep);
1873
                }
1874
            }
1875
        } // if ($deep)
1876
1877
        // i18n behavior
1878
        $this->currentLocale = 'ru';
1879
        $this->currentTranslations = null;
1880
1881
        $this->collBannerImages = null;
1882
        $this->collBannersI18ns = null;
1883
    }
1884
1885
    /**
1886
     * Return the string representation of this object
1887
     *
1888
     * @return string
1889
     */
1890
    public function __toString()
1891
    {
1892
        return (string) $this->exportTo(BannersTableMap::DEFAULT_STRING_FORMAT);
1893
    }
1894
1895
    // i18n behavior
1896
1897
    /**
1898
     * Sets the locale for translations
1899
     *
1900
     * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
1901
     *
1902
     * @return    $this|ChildBanners The current object (for fluent API support)
1903
     */
1904
    public function setLocale($locale = 'ru')
1905
    {
1906
        $this->currentLocale = $locale;
1907
1908
        return $this;
1909
    }
1910
1911
    /**
1912
     * Gets the locale for translations
1913
     *
1914
     * @return    string $locale Locale to use for the translation, e.g. 'fr_FR'
1915
     */
1916
    public function getLocale()
1917
    {
1918
        return $this->currentLocale;
1919
    }
1920
1921
    /**
1922
     * Returns the current translation for a given locale
1923
     *
1924
     * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
1925
     * @param     ConnectionInterface $con an optional connection object
1926
     *
1927
     * @return ChildBannersI18n */
1928 View Code Duplication
    public function getTranslation($locale = 'ru', ConnectionInterface $con = null)
1929
    {
1930
        if (!isset($this->currentTranslations[$locale])) {
1931
            if (null !== $this->collBannersI18ns) {
1932
                foreach ($this->collBannersI18ns as $translation) {
1933
                    if ($translation->getLocale() == $locale) {
1934
                        $this->currentTranslations[$locale] = $translation;
1935
1936
                        return $translation;
1937
                    }
1938
                }
1939
            }
1940
            if ($this->isNew()) {
1941
                $translation = new ChildBannersI18n();
1942
                $translation->setLocale($locale);
1943
            } else {
1944
                $translation = ChildBannersI18nQuery::create()
1945
                    ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
1946
                    ->findOneOrCreate($con);
0 ignored issues
show
Bug introduced by
It seems like $con defined by parameter $con on line 1928 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...
1947
                $this->currentTranslations[$locale] = $translation;
1948
            }
1949
            $this->addBannersI18n($translation);
1950
        }
1951
1952
        return $this->currentTranslations[$locale];
1953
    }
1954
1955
    /**
1956
     * Remove the translation for a given locale
1957
     *
1958
     * @param     string $locale Locale to use for the translation, e.g. 'fr_FR'
1959
     * @param     ConnectionInterface $con an optional connection object
1960
     *
1961
     * @return    $this|ChildBanners The current object (for fluent API support)
1962
     */
1963 View Code Duplication
    public function removeTranslation($locale = 'ru', ConnectionInterface $con = null)
1964
    {
1965
        if (!$this->isNew()) {
1966
            ChildBannersI18nQuery::create()
1967
                ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
1968
                ->delete($con);
1969
        }
1970
        if (isset($this->currentTranslations[$locale])) {
1971
            unset($this->currentTranslations[$locale]);
1972
        }
1973
        foreach ($this->collBannersI18ns as $key => $translation) {
1974
            if ($translation->getLocale() == $locale) {
1975
                unset($this->collBannersI18ns[$key]);
1976
                break;
1977
            }
1978
        }
1979
1980
        return $this;
1981
    }
1982
1983
    /**
1984
     * Returns the current translation
1985
     *
1986
     * @param     ConnectionInterface $con an optional connection object
1987
     *
1988
     * @return ChildBannersI18n */
1989
    public function getCurrentTranslation(ConnectionInterface $con = null)
1990
    {
1991
        return $this->getTranslation($this->getLocale(), $con);
1992
    }
1993
1994
1995
        /**
1996
         * Get the [name] column value.
1997
         *
1998
         * @return string
1999
         */
2000
        public function getName()
2001
        {
2002
        return $this->getCurrentTranslation()->getName();
2003
    }
2004
2005
2006
        /**
2007
         * Set the value of [name] column.
2008
         *
2009
         * @param string $v new value
2010
         * @return $this|\xbanners\models\BannersI18n The current object (for fluent API support)
2011
         */
2012
        public function setName($v)
2013
        {    $this->getCurrentTranslation()->setName($v);
2014
2015
        return $this;
2016
    }
2017
2018
    /**
2019
     * Code to be run before persisting the object
2020
     * @param  ConnectionInterface $con
2021
     * @return boolean
2022
     */
2023
    public function preSave(ConnectionInterface $con = null)
2024
    {
2025
        if (is_callable('parent::preSave')) {
2026
            return parent::preSave($con);
2027
        }
2028
        return true;
2029
    }
2030
2031
    /**
2032
     * Code to be run after persisting the object
2033
     * @param ConnectionInterface $con
2034
     */
2035
    public function postSave(ConnectionInterface $con = null)
2036
    {
2037
        if (is_callable('parent::postSave')) {
2038
            parent::postSave($con);
2039
        }
2040
    }
2041
2042
    /**
2043
     * Code to be run before inserting to database
2044
     * @param  ConnectionInterface $con
2045
     * @return boolean
2046
     */
2047
    public function preInsert(ConnectionInterface $con = null)
2048
    {
2049
        if (is_callable('parent::preInsert')) {
2050
            return parent::preInsert($con);
2051
        }
2052
        return true;
2053
    }
2054
2055
    /**
2056
     * Code to be run after inserting to database
2057
     * @param ConnectionInterface $con
2058
     */
2059
    public function postInsert(ConnectionInterface $con = null)
2060
    {
2061
        if (is_callable('parent::postInsert')) {
2062
            parent::postInsert($con);
2063
        }
2064
    }
2065
2066
    /**
2067
     * Code to be run before updating the object in database
2068
     * @param  ConnectionInterface $con
2069
     * @return boolean
2070
     */
2071
    public function preUpdate(ConnectionInterface $con = null)
2072
    {
2073
        if (is_callable('parent::preUpdate')) {
2074
            return parent::preUpdate($con);
2075
        }
2076
        return true;
2077
    }
2078
2079
    /**
2080
     * Code to be run after updating the object in database
2081
     * @param ConnectionInterface $con
2082
     */
2083
    public function postUpdate(ConnectionInterface $con = null)
2084
    {
2085
        if (is_callable('parent::postUpdate')) {
2086
            parent::postUpdate($con);
2087
        }
2088
    }
2089
2090
    /**
2091
     * Code to be run before deleting the object in database
2092
     * @param  ConnectionInterface $con
2093
     * @return boolean
2094
     */
2095
    public function preDelete(ConnectionInterface $con = null)
2096
    {
2097
        if (is_callable('parent::preDelete')) {
2098
            return parent::preDelete($con);
2099
        }
2100
        return true;
2101
    }
2102
2103
    /**
2104
     * Code to be run after deleting the object in database
2105
     * @param ConnectionInterface $con
2106
     */
2107
    public function postDelete(ConnectionInterface $con = null)
2108
    {
2109
        if (is_callable('parent::postDelete')) {
2110
            parent::postDelete($con);
2111
        }
2112
    }
2113
2114
2115
    /**
2116
     * Derived method to catches calls to undefined methods.
2117
     *
2118
     * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
2119
     * Allows to define default __call() behavior if you overwrite __call()
2120
     *
2121
     * @param string $name
2122
     * @param mixed  $params
2123
     *
2124
     * @return array|string
2125
     */
2126 View Code Duplication
    public function __call($name, $params)
2127
    {
2128
        if (0 === strpos($name, 'get')) {
2129
            $virtualColumn = substr($name, 3);
2130
            if ($this->hasVirtualColumn($virtualColumn)) {
2131
                return $this->getVirtualColumn($virtualColumn);
2132
            }
2133
2134
            $virtualColumn = lcfirst($virtualColumn);
2135
            if ($this->hasVirtualColumn($virtualColumn)) {
2136
                return $this->getVirtualColumn($virtualColumn);
2137
            }
2138
        }
2139
2140
        if (0 === strpos($name, 'from')) {
2141
            $format = substr($name, 4);
2142
2143
            return $this->importFrom($format, reset($params));
2144
        }
2145
2146
        if (0 === strpos($name, 'to')) {
2147
            $format = substr($name, 2);
2148
            $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
2149
2150
            return $this->exportTo($format, $includeLazyLoadColumns);
2151
        }
2152
2153
        throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
2154
    }
2155
2156
}
2157