BannerImageI18n   F
last analyzed

Complexity

Total Complexity 205

Size/Duplication

Total Lines 1497
Duplicated Lines 28.39 %

Coupling/Cohesion

Components 1
Dependencies 13

Importance

Changes 0
Metric Value
dl 425
loc 1497
rs 0.8
c 0
b 0
f 0
wmc 205
lcom 1
cbo 13

68 Methods

Rating   Name   Duplication   Size   Complexity  
A applyDefaultValues() 0 4 1
A __construct() 0 4 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 getLocale() 0 4 1
A getSrc() 0 4 1
A getName() 0 4 1
A getClicks() 0 4 1
A getDescription() 0 4 1
A setId() 17 17 5
A setLocale() 13 13 3
A setSrc() 13 13 3
A setName() 13 13 3
A setClicks() 13 13 3
A setDescription() 13 13 3
A hasOnlyDefaultValues() 0 9 2
F hydrate() 35 35 15
A ensureConsistency() 0 6 3
B reload() 30 30 6
A delete() 21 21 4
B save() 38 38 9
B doSave() 35 35 8
F doInsert() 0 64 15
A doUpdate() 0 7 1
A getByName() 7 7 1
B getByPosition() 0 26 7
B toArray() 0 41 7
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 8 1
B hashCode() 23 23 6
A getPrimaryKey() 8 8 1
A setPrimaryKey() 0 5 1
A isPrimaryKeyNull() 0 4 2
A copyInto() 0 12 2
A copy() 9 9 1
A setBannerImage() 19 19 3
A getBannerImage() 0 15 3
A clear() 0 18 2
A clearAllReferences() 0 7 2
A __toString() 0 4 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 BannerImageI18n 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 BannerImageI18n, 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\Connection\ConnectionInterface;
14
use Propel\Runtime\Exception\BadMethodCallException;
15
use Propel\Runtime\Exception\LogicException;
16
use Propel\Runtime\Exception\PropelException;
17
use Propel\Runtime\Map\TableMap;
18
use Propel\Runtime\Parser\AbstractParser;
19
use xbanners\models\BannerImage as ChildBannerImage;
20
use xbanners\models\BannerImageI18nQuery as ChildBannerImageI18nQuery;
21
use xbanners\models\BannerImageQuery as ChildBannerImageQuery;
22
use xbanners\models\Map\BannerImageI18nTableMap;
23
24
/**
25
 * Base class that represents a row from the 'banner_image_i18n' table.
26
 *
27
 *
28
 *
29
 * @package    propel.generator.xbanners.models.Base
30
 */
31
abstract class BannerImageI18n extends PropelBaseModelClass implements ActiveRecordInterface
32
{
33
    /**
34
     * TableMap class name
35
     */
36
    const TABLE_MAP = '\\xbanners\\models\\Map\\BannerImageI18nTableMap';
37
38
39
    /**
40
     * attribute to determine if this object has previously been saved.
41
     * @var boolean
42
     */
43
    protected $new = true;
44
45
    /**
46
     * attribute to determine whether this object has been deleted.
47
     * @var boolean
48
     */
49
    protected $deleted = false;
50
51
    /**
52
     * The columns that have been modified in current object.
53
     * Tracking modified columns allows us to only update modified columns.
54
     * @var array
55
     */
56
    protected $modifiedColumns = array();
57
58
    /**
59
     * The (virtual) columns that are added at runtime
60
     * The formatters can add supplementary columns based on a resultset
61
     * @var array
62
     */
63
    protected $virtualColumns = array();
64
65
    /**
66
     * The value for the id field.
67
     *
68
     * @var        int
69
     */
70
    protected $id;
71
72
    /**
73
     * The value for the locale field.
74
     *
75
     * Note: this column has a database default value of: 'ru'
76
     * @var        string
77
     */
78
    protected $locale;
79
80
    /**
81
     * The value for the src field.
82
     *
83
     * @var        string
84
     */
85
    protected $src;
86
87
    /**
88
     * The value for the name field.
89
     *
90
     * @var        string
91
     */
92
    protected $name;
93
94
    /**
95
     * The value for the clicks field.
96
     *
97
     * @var        int
98
     */
99
    protected $clicks;
100
101
    /**
102
     * The value for the description field.
103
     *
104
     * @var        string
105
     */
106
    protected $description;
107
108
    /**
109
     * @var        ChildBannerImage
110
     */
111
    protected $aBannerImage;
112
113
    /**
114
     * Flag to prevent endless save loop, if this object is referenced
115
     * by another object which falls in this transaction.
116
     *
117
     * @var boolean
118
     */
119
    protected $alreadyInSave = false;
120
121
    /**
122
     * Applies default values to this object.
123
     * This method should be called from the object's constructor (or
124
     * equivalent initialization method).
125
     * @see __construct()
126
     */
127
    public function applyDefaultValues()
128
    {
129
        $this->locale = 'ru';
130
    }
131
132
    /**
133
     * Initializes internal state of xbanners\models\Base\BannerImageI18n object.
134
     * @see applyDefaults()
135
     */
136
    public function __construct()
137
    {
138
        $this->applyDefaultValues();
139
    }
140
141
    /**
142
     * Returns whether the object has been modified.
143
     *
144
     * @return boolean True if the object has been modified.
145
     */
146
    public function isModified()
147
    {
148
        return !!$this->modifiedColumns;
149
    }
150
151
    /**
152
     * Has specified column been modified?
153
     *
154
     * @param  string  $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID
155
     * @return boolean True if $col has been modified.
156
     */
157
    public function isColumnModified($col)
158
    {
159
        return $this->modifiedColumns && isset($this->modifiedColumns[$col]);
160
    }
161
162
    /**
163
     * Get the columns that have been modified in this object.
164
     * @return array A unique list of the modified column names for this object.
165
     */
166
    public function getModifiedColumns()
167
    {
168
        return $this->modifiedColumns ? array_keys($this->modifiedColumns) : [];
169
    }
170
171
    /**
172
     * Returns whether the object has ever been saved.  This will
173
     * be false, if the object was retrieved from storage or was created
174
     * and then saved.
175
     *
176
     * @return boolean true, if the object has never been persisted.
177
     */
178
    public function isNew()
179
    {
180
        return $this->new;
181
    }
182
183
    /**
184
     * Setter for the isNew attribute.  This method will be called
185
     * by Propel-generated children and objects.
186
     *
187
     * @param boolean $b the state of the object.
188
     */
189
    public function setNew($b)
190
    {
191
        $this->new = (boolean) $b;
192
    }
193
194
    /**
195
     * Whether this object has been deleted.
196
     * @return boolean The deleted state of this object.
197
     */
198
    public function isDeleted()
199
    {
200
        return $this->deleted;
201
    }
202
203
    /**
204
     * Specify whether this object has been deleted.
205
     * @param  boolean $b The deleted state of this object.
206
     * @return void
207
     */
208
    public function setDeleted($b)
209
    {
210
        $this->deleted = (boolean) $b;
211
    }
212
213
    /**
214
     * Sets the modified state for the object to be false.
215
     * @param  string $col If supplied, only the specified column is reset.
216
     * @return void
217
     */
218 View Code Duplication
    public function resetModified($col = null)
219
    {
220
        if (null !== $col) {
221
            if (isset($this->modifiedColumns[$col])) {
222
                unset($this->modifiedColumns[$col]);
223
            }
224
        } else {
225
            $this->modifiedColumns = array();
226
        }
227
    }
228
229
    /**
230
     * Compares this with another <code>BannerImageI18n</code> instance.  If
231
     * <code>obj</code> is an instance of <code>BannerImageI18n</code>, delegates to
232
     * <code>equals(BannerImageI18n)</code>.  Otherwise, returns <code>false</code>.
233
     *
234
     * @param  mixed   $obj The object to compare to.
235
     * @return boolean Whether equal to the object specified.
236
     */
237 View Code Duplication
    public function equals($obj)
238
    {
239
        if (!$obj instanceof static) {
240
            return false;
241
        }
242
243
        if ($this === $obj) {
244
            return true;
245
        }
246
247
        if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) {
248
            return false;
249
        }
250
251
        return $this->getPrimaryKey() === $obj->getPrimaryKey();
252
    }
253
254
    /**
255
     * Get the associative array of the virtual columns in this object
256
     *
257
     * @return array
258
     */
259
    public function getVirtualColumns()
260
    {
261
        return $this->virtualColumns;
262
    }
263
264
    /**
265
     * Checks the existence of a virtual column in this object
266
     *
267
     * @param  string  $name The virtual column name
268
     * @return boolean
269
     */
270
    public function hasVirtualColumn($name)
271
    {
272
        return array_key_exists($name, $this->virtualColumns);
273
    }
274
275
    /**
276
     * Get the value of a virtual column in this object
277
     *
278
     * @param  string $name The virtual column name
279
     * @return mixed
280
     *
281
     * @throws PropelException
282
     */
283 View Code Duplication
    public function getVirtualColumn($name)
284
    {
285
        if (!$this->hasVirtualColumn($name)) {
286
            throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name));
287
        }
288
289
        return $this->virtualColumns[$name];
290
    }
291
292
    /**
293
     * Set the value of a virtual column in this object
294
     *
295
     * @param string $name  The virtual column name
296
     * @param mixed  $value The value to give to the virtual column
297
     *
298
     * @return $this|BannerImageI18n The current object, for fluid interface
299
     */
300
    public function setVirtualColumn($name, $value)
301
    {
302
        $this->virtualColumns[$name] = $value;
303
304
        return $this;
305
    }
306
307
    /**
308
     * Logs a message using Propel::log().
309
     *
310
     * @param  string  $msg
311
     * @param  int     $priority One of the Propel::LOG_* logging levels
312
     * @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...
313
     */
314
    protected function log($msg, $priority = Propel::LOG_INFO)
315
    {
316
        return Propel::log(get_class($this) . ': ' . $msg, $priority);
317
    }
318
319
    /**
320
     * Export the current object properties to a string, using a given parser format
321
     * <code>
322
     * $book = BookQuery::create()->findPk(9012);
323
     * echo $book->exportTo('JSON');
324
     *  => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
325
     * </code>
326
     *
327
     * @param  mixed   $parser                 A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
328
     * @param  boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
329
     * @return string  The exported data
330
     */
331 View Code Duplication
    public function exportTo($parser, $includeLazyLoadColumns = true)
332
    {
333
        if (!$parser instanceof AbstractParser) {
334
            $parser = AbstractParser::getParser($parser);
335
        }
336
337
        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\BannerImageI18n::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...
338
    }
339
340
    /**
341
     * Clean up internal collections prior to serializing
342
     * Avoids recursive loops that turn into segmentation faults when serializing
343
     */
344 View Code Duplication
    public function __sleep()
345
    {
346
        $this->clearAllReferences();
347
348
        $cls = new \ReflectionClass($this);
349
        $propertyNames = [];
350
        $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC));
351
352
        foreach($serializableProperties as $property) {
353
            $propertyNames[] = $property->getName();
354
        }
355
356
        return $propertyNames;
357
    }
358
359
    /**
360
     * Get the [id] column value.
361
     *
362
     * @return int
363
     */
364
    public function getId()
365
    {
366
        return $this->id;
367
    }
368
369
    /**
370
     * Get the [locale] column value.
371
     *
372
     * @return string
373
     */
374
    public function getLocale()
375
    {
376
        return $this->locale;
377
    }
378
379
    /**
380
     * Get the [src] column value.
381
     *
382
     * @return string
383
     */
384
    public function getSrc()
385
    {
386
        return $this->src;
387
    }
388
389
    /**
390
     * Get the [name] column value.
391
     *
392
     * @return string
393
     */
394
    public function getName()
395
    {
396
        return $this->name;
397
    }
398
399
    /**
400
     * Get the [clicks] column value.
401
     *
402
     * @return int
403
     */
404
    public function getClicks()
405
    {
406
        return $this->clicks;
407
    }
408
409
    /**
410
     * Get the [description] column value.
411
     *
412
     * @return string
413
     */
414
    public function getDescription()
415
    {
416
        return $this->description;
417
    }
418
419
    /**
420
     * Set the value of [id] column.
421
     *
422
     * @param int $v new value
423
     * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
424
     */
425 View Code Duplication
    public function setId($v)
426
    {
427
        if ($v !== null) {
428
            $v = (int) $v;
429
        }
430
431
        if ($this->id !== $v) {
432
            $this->id = $v;
433
            $this->modifiedColumns[BannerImageI18nTableMap::COL_ID] = true;
434
        }
435
436
        if ($this->aBannerImage !== null && $this->aBannerImage->getId() !== $v) {
437
            $this->aBannerImage = null;
438
        }
439
440
        return $this;
441
    } // setId()
442
443
    /**
444
     * Set the value of [locale] column.
445
     *
446
     * @param string $v new value
447
     * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
448
     */
449 View Code Duplication
    public function setLocale($v)
450
    {
451
        if ($v !== null) {
452
            $v = (string) $v;
453
        }
454
455
        if ($this->locale !== $v) {
456
            $this->locale = $v;
457
            $this->modifiedColumns[BannerImageI18nTableMap::COL_LOCALE] = true;
458
        }
459
460
        return $this;
461
    } // setLocale()
462
463
    /**
464
     * Set the value of [src] column.
465
     *
466
     * @param string $v new value
467
     * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
468
     */
469 View Code Duplication
    public function setSrc($v)
470
    {
471
        if ($v !== null) {
472
            $v = (string) $v;
473
        }
474
475
        if ($this->src !== $v) {
476
            $this->src = $v;
477
            $this->modifiedColumns[BannerImageI18nTableMap::COL_SRC] = true;
478
        }
479
480
        return $this;
481
    } // setSrc()
482
483
    /**
484
     * Set the value of [name] column.
485
     *
486
     * @param string $v new value
487
     * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
488
     */
489 View Code Duplication
    public function setName($v)
490
    {
491
        if ($v !== null) {
492
            $v = (string) $v;
493
        }
494
495
        if ($this->name !== $v) {
496
            $this->name = $v;
497
            $this->modifiedColumns[BannerImageI18nTableMap::COL_NAME] = true;
498
        }
499
500
        return $this;
501
    } // setName()
502
503
    /**
504
     * Set the value of [clicks] column.
505
     *
506
     * @param int $v new value
507
     * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
508
     */
509 View Code Duplication
    public function setClicks($v)
510
    {
511
        if ($v !== null) {
512
            $v = (int) $v;
513
        }
514
515
        if ($this->clicks !== $v) {
516
            $this->clicks = $v;
517
            $this->modifiedColumns[BannerImageI18nTableMap::COL_CLICKS] = true;
518
        }
519
520
        return $this;
521
    } // setClicks()
522
523
    /**
524
     * Set the value of [description] column.
525
     *
526
     * @param string $v new value
527
     * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
528
     */
529 View Code Duplication
    public function setDescription($v)
530
    {
531
        if ($v !== null) {
532
            $v = (string) $v;
533
        }
534
535
        if ($this->description !== $v) {
536
            $this->description = $v;
537
            $this->modifiedColumns[BannerImageI18nTableMap::COL_DESCRIPTION] = true;
538
        }
539
540
        return $this;
541
    } // setDescription()
542
543
    /**
544
     * Indicates whether the columns in this object are only set to default values.
545
     *
546
     * This method can be used in conjunction with isModified() to indicate whether an object is both
547
     * modified _and_ has some values set which are non-default.
548
     *
549
     * @return boolean Whether the columns in this object are only been set with default values.
550
     */
551
    public function hasOnlyDefaultValues()
552
    {
553
            if ($this->locale !== 'ru') {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return !($this->locale !== 'ru');.
Loading history...
554
                return false;
555
            }
556
557
        // otherwise, everything was equal, so return TRUE
558
        return true;
559
    } // hasOnlyDefaultValues()
560
561
    /**
562
     * Hydrates (populates) the object variables with values from the database resultset.
563
     *
564
     * An offset (0-based "start column") is specified so that objects can be hydrated
565
     * with a subset of the columns in the resultset rows.  This is needed, for example,
566
     * for results of JOIN queries where the resultset row includes columns from two or
567
     * more tables.
568
     *
569
     * @param array   $row       The row returned by DataFetcher->fetch().
570
     * @param int     $startcol  0-based offset column which indicates which restultset column to start with.
571
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
572
     * @param string  $indexType The index type of $row. Mostly DataFetcher->getIndexType().
573
                                  One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
574
     *                            TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
575
     *
576
     * @return int             next starting column
577
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
578
     */
579 View Code Duplication
    public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM)
580
    {
581
        try {
582
583
            $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : BannerImageI18nTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
584
            $this->id = (null !== $col) ? (int) $col : null;
585
586
            $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : BannerImageI18nTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)];
587
            $this->locale = (null !== $col) ? (string) $col : null;
588
589
            $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : BannerImageI18nTableMap::translateFieldName('Src', TableMap::TYPE_PHPNAME, $indexType)];
590
            $this->src = (null !== $col) ? (string) $col : null;
591
592
            $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : BannerImageI18nTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)];
593
            $this->name = (null !== $col) ? (string) $col : null;
594
595
            $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : BannerImageI18nTableMap::translateFieldName('Clicks', TableMap::TYPE_PHPNAME, $indexType)];
596
            $this->clicks = (null !== $col) ? (int) $col : null;
597
598
            $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : BannerImageI18nTableMap::translateFieldName('Description', TableMap::TYPE_PHPNAME, $indexType)];
599
            $this->description = (null !== $col) ? (string) $col : null;
600
            $this->resetModified();
601
602
            $this->setNew(false);
603
604
            if ($rehydrate) {
605
                $this->ensureConsistency();
606
            }
607
608
            return $startcol + 6; // 6 = BannerImageI18nTableMap::NUM_HYDRATE_COLUMNS.
609
610
        } catch (Exception $e) {
611
            throw new PropelException(sprintf('Error populating %s object', '\\xbanners\\models\\BannerImageI18n'), 0, $e);
612
        }
613
    }
614
615
    /**
616
     * Checks and repairs the internal consistency of the object.
617
     *
618
     * This method is executed after an already-instantiated object is re-hydrated
619
     * from the database.  It exists to check any foreign keys to make sure that
620
     * the objects related to the current object are correct based on foreign key.
621
     *
622
     * You can override this method in the stub class, but you should always invoke
623
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
624
     * in case your model changes.
625
     *
626
     * @throws PropelException
627
     */
628
    public function ensureConsistency()
629
    {
630
        if ($this->aBannerImage !== null && $this->id !== $this->aBannerImage->getId()) {
631
            $this->aBannerImage = null;
632
        }
633
    } // ensureConsistency
634
635
    /**
636
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
637
     *
638
     * This will only work if the object has been saved and has a valid primary key set.
639
     *
640
     * @param      boolean $deep (optional) Whether to also de-associated any related objects.
641
     * @param      ConnectionInterface $con (optional) The ConnectionInterface connection to use.
642
     * @return void
643
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
644
     */
645 View Code Duplication
    public function reload($deep = false, ConnectionInterface $con = null)
646
    {
647
        if ($this->isDeleted()) {
648
            throw new PropelException("Cannot reload a deleted object.");
649
        }
650
651
        if ($this->isNew()) {
652
            throw new PropelException("Cannot reload an unsaved object.");
653
        }
654
655
        if ($con === null) {
656
            $con = Propel::getServiceContainer()->getReadConnection(BannerImageI18nTableMap::DATABASE_NAME);
657
        }
658
659
        // We don't need to alter the object instance pool; we're just modifying this instance
660
        // already in the pool.
661
662
        $dataFetcher = ChildBannerImageI18nQuery::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...
663
        $row = $dataFetcher->fetch();
664
        $dataFetcher->close();
665
        if (!$row) {
666
            throw new PropelException('Cannot find matching row in the database to reload object values.');
667
        }
668
        $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate
669
670
        if ($deep) {  // also de-associate any related objects?
671
672
            $this->aBannerImage = null;
673
        } // if (deep)
674
    }
675
676
    /**
677
     * Removes this object from datastore and sets delete attribute.
678
     *
679
     * @param      ConnectionInterface $con
680
     * @return void
681
     * @throws PropelException
682
     * @see BannerImageI18n::setDeleted()
683
     * @see BannerImageI18n::isDeleted()
684
     */
685 View Code Duplication
    public function delete(ConnectionInterface $con = null)
686
    {
687
        if ($this->isDeleted()) {
688
            throw new PropelException("This object has already been deleted.");
689
        }
690
691
        if ($con === null) {
692
            $con = Propel::getServiceContainer()->getWriteConnection(BannerImageI18nTableMap::DATABASE_NAME);
693
        }
694
695
        $con->transaction(function () use ($con) {
696
            $deleteQuery = ChildBannerImageI18nQuery::create()
697
                ->filterByPrimaryKey($this->getPrimaryKey());
698
            $ret = $this->preDelete($con);
699
            if ($ret) {
700
                $deleteQuery->delete($con);
701
                $this->postDelete($con);
702
                $this->setDeleted(true);
703
            }
704
        });
705
    }
706
707
    /**
708
     * Persists this object to the database.
709
     *
710
     * If the object is new, it inserts it; otherwise an update is performed.
711
     * All modified related objects will also be persisted in the doSave()
712
     * method.  This method wraps all precipitate database operations in a
713
     * single transaction.
714
     *
715
     * @param      ConnectionInterface $con
716
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
717
     * @throws PropelException
718
     * @see doSave()
719
     */
720 View Code Duplication
    public function save(ConnectionInterface $con = null)
721
    {
722
        if ($this->isDeleted()) {
723
            throw new PropelException("You cannot save an object that has been deleted.");
724
        }
725
726
        if ($this->alreadyInSave) {
727
            return 0;
728
        }
729
730
        if ($con === null) {
731
            $con = Propel::getServiceContainer()->getWriteConnection(BannerImageI18nTableMap::DATABASE_NAME);
732
        }
733
734
        return $con->transaction(function () use ($con) {
735
            $ret = $this->preSave($con);
736
            $isInsert = $this->isNew();
737
            if ($isInsert) {
738
                $ret = $ret && $this->preInsert($con);
739
            } else {
740
                $ret = $ret && $this->preUpdate($con);
741
            }
742
            if ($ret) {
743
                $affectedRows = $this->doSave($con);
744
                if ($isInsert) {
745
                    $this->postInsert($con);
746
                } else {
747
                    $this->postUpdate($con);
748
                }
749
                $this->postSave($con);
750
                BannerImageI18nTableMap::addInstanceToPool($this);
0 ignored issues
show
Compatibility introduced by
$this of type object<xbanners\models\Base\BannerImageI18n> is not a sub-type of object<xbanners\models\BannerImageI18n>. It seems like you assume a child class of the class xbanners\models\Base\BannerImageI18n to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
751
            } else {
752
                $affectedRows = 0;
753
            }
754
755
            return $affectedRows;
756
        });
757
    }
758
759
    /**
760
     * Performs the work of inserting or updating the row in the database.
761
     *
762
     * If the object is new, it inserts it; otherwise an update is performed.
763
     * All related objects are also updated in this method.
764
     *
765
     * @param      ConnectionInterface $con
766
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
767
     * @throws PropelException
768
     * @see save()
769
     */
770 View Code Duplication
    protected function doSave(ConnectionInterface $con)
771
    {
772
        $affectedRows = 0; // initialize var to track total num of affected rows
773
        if (!$this->alreadyInSave) {
774
            $this->alreadyInSave = true;
775
776
            // We call the save method on the following object(s) if they
777
            // were passed to this object by their corresponding set
778
            // method.  This object relates to these object(s) by a
779
            // foreign key reference.
780
781
            if ($this->aBannerImage !== null) {
782
                if ($this->aBannerImage->isModified() || $this->aBannerImage->isNew()) {
783
                    $affectedRows += $this->aBannerImage->save($con);
784
                }
785
                $this->setBannerImage($this->aBannerImage);
786
            }
787
788
            if ($this->isNew() || $this->isModified()) {
789
                // persist changes
790
                if ($this->isNew()) {
791
                    $this->doInsert($con);
792
                    $affectedRows += 1;
793
                } else {
794
                    $affectedRows += $this->doUpdate($con);
795
                }
796
                $this->resetModified();
797
            }
798
799
            $this->alreadyInSave = false;
800
801
        }
802
803
        return $affectedRows;
804
    } // doSave()
805
806
    /**
807
     * Insert the row in the database.
808
     *
809
     * @param      ConnectionInterface $con
810
     *
811
     * @throws PropelException
812
     * @see doSave()
813
     */
814
    protected function doInsert(ConnectionInterface $con)
815
    {
816
        $modifiedColumns = array();
817
        $index = 0;
818
819
820
         // check the columns in natural order for more readable SQL queries
821
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_ID)) {
822
            $modifiedColumns[':p' . $index++]  = 'id';
823
        }
824
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_LOCALE)) {
825
            $modifiedColumns[':p' . $index++]  = 'locale';
826
        }
827
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_SRC)) {
828
            $modifiedColumns[':p' . $index++]  = 'src';
829
        }
830
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_NAME)) {
831
            $modifiedColumns[':p' . $index++]  = 'name';
832
        }
833
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_CLICKS)) {
834
            $modifiedColumns[':p' . $index++]  = 'clicks';
835
        }
836
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_DESCRIPTION)) {
837
            $modifiedColumns[':p' . $index++]  = 'description';
838
        }
839
840
        $sql = sprintf(
841
            'INSERT INTO banner_image_i18n (%s) VALUES (%s)',
842
            implode(', ', $modifiedColumns),
843
            implode(', ', array_keys($modifiedColumns))
844
        );
845
846
        try {
847
            $stmt = $con->prepare($sql);
848
            foreach ($modifiedColumns as $identifier => $columnName) {
849
                switch ($columnName) {
850
                    case 'id':
851
                        $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
852
                        break;
853
                    case 'locale':
854
                        $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR);
855
                        break;
856
                    case 'src':
857
                        $stmt->bindValue($identifier, $this->src, PDO::PARAM_STR);
858
                        break;
859
                    case 'name':
860
                        $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR);
861
                        break;
862
                    case 'clicks':
863
                        $stmt->bindValue($identifier, $this->clicks, PDO::PARAM_INT);
864
                        break;
865
                    case 'description':
866
                        $stmt->bindValue($identifier, $this->description, PDO::PARAM_STR);
867
                        break;
868
                }
869
            }
870
            $stmt->execute();
871
        } catch (Exception $e) {
872
            Propel::log($e->getMessage(), Propel::LOG_ERR);
873
            throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
874
        }
875
876
        $this->setNew(false);
877
    }
878
879
    /**
880
     * Update the row in the database.
881
     *
882
     * @param      ConnectionInterface $con
883
     *
884
     * @return Integer Number of updated rows
885
     * @see doSave()
886
     */
887
    protected function doUpdate(ConnectionInterface $con)
888
    {
889
        $selectCriteria = $this->buildPkeyCriteria();
890
        $valuesCriteria = $this->buildCriteria();
891
892
        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...
893
    }
894
895
    /**
896
     * Retrieves a field from the object by name passed in as a string.
897
     *
898
     * @param      string $name name
899
     * @param      string $type The type of fieldname the $name is of:
900
     *                     one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
901
     *                     TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
902
     *                     Defaults to TableMap::TYPE_PHPNAME.
903
     * @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...
904
     */
905 View Code Duplication
    public function getByName($name, $type = TableMap::TYPE_PHPNAME)
906
    {
907
        $pos = BannerImageI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
908
        $field = $this->getByPosition($pos);
909
910
        return $field;
911
    }
912
913
    /**
914
     * Retrieves a field from the object by Position as specified in the xml schema.
915
     * Zero-based.
916
     *
917
     * @param      int $pos position in xml schema
918
     * @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...
919
     */
920
    public function getByPosition($pos)
921
    {
922
        switch ($pos) {
923
            case 0:
924
                return $this->getId();
925
                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...
926
            case 1:
927
                return $this->getLocale();
928
                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...
929
            case 2:
930
                return $this->getSrc();
931
                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...
932
            case 3:
933
                return $this->getName();
934
                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...
935
            case 4:
936
                return $this->getClicks();
937
                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...
938
            case 5:
939
                return $this->getDescription();
940
                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...
941
            default:
942
                return null;
943
                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...
944
        } // switch()
945
    }
946
947
    /**
948
     * Exports the object as an array.
949
     *
950
     * You can specify the key type of the array by passing one of the class
951
     * type constants.
952
     *
953
     * @param     string  $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
954
     *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
955
     *                    Defaults to TableMap::TYPE_PHPNAME.
956
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
957
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
958
     * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
959
     *
960
     * @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<*,integer|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...
961
     */
962
    public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
963
    {
964
965
        if (isset($alreadyDumpedObjects['BannerImageI18n'][$this->hashCode()])) {
966
            return '*RECURSION*';
967
        }
968
        $alreadyDumpedObjects['BannerImageI18n'][$this->hashCode()] = true;
969
        $keys = BannerImageI18nTableMap::getFieldNames($keyType);
970
        $result = array(
971
            $keys[0] => $this->getId(),
972
            $keys[1] => $this->getLocale(),
973
            $keys[2] => $this->getSrc(),
974
            $keys[3] => $this->getName(),
975
            $keys[4] => $this->getClicks(),
976
            $keys[5] => $this->getDescription(),
977
        );
978
        $virtualColumns = $this->virtualColumns;
979
        foreach ($virtualColumns as $key => $virtualColumn) {
980
            $result[$key] = $virtualColumn;
981
        }
982
983
        if ($includeForeignObjects) {
984
            if (null !== $this->aBannerImage) {
985
986
                switch ($keyType) {
987
                    case TableMap::TYPE_CAMELNAME:
988
                        $key = 'bannerImage';
989
                        break;
990
                    case TableMap::TYPE_FIELDNAME:
991
                        $key = 'banner_image';
992
                        break;
993
                    default:
994
                        $key = 'BannerImage';
995
                }
996
997
                $result[$key] = $this->aBannerImage->toArray($keyType, $includeLazyLoadColumns,  $alreadyDumpedObjects, true);
998
            }
999
        }
1000
1001
        return $result;
1002
    }
1003
1004
    /**
1005
     * Sets a field from the object by name passed in as a string.
1006
     *
1007
     * @param  string $name
1008
     * @param  mixed  $value field value
1009
     * @param  string $type The type of fieldname the $name is of:
1010
     *                one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
1011
     *                TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1012
     *                Defaults to TableMap::TYPE_PHPNAME.
1013
     * @return $this|\xbanners\models\BannerImageI18n
1014
     */
1015
    public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME)
1016
    {
1017
        $pos = BannerImageI18nTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
1018
1019
        return $this->setByPosition($pos, $value);
1020
    }
1021
1022
    /**
1023
     * Sets a field from the object by Position as specified in the xml schema.
1024
     * Zero-based.
1025
     *
1026
     * @param  int $pos position in xml schema
1027
     * @param  mixed $value field value
1028
     * @return $this|\xbanners\models\BannerImageI18n
1029
     */
1030
    public function setByPosition($pos, $value)
1031
    {
1032
        switch ($pos) {
1033
            case 0:
1034
                $this->setId($value);
1035
                break;
1036
            case 1:
1037
                $this->setLocale($value);
1038
                break;
1039
            case 2:
1040
                $this->setSrc($value);
1041
                break;
1042
            case 3:
1043
                $this->setName($value);
1044
                break;
1045
            case 4:
1046
                $this->setClicks($value);
1047
                break;
1048
            case 5:
1049
                $this->setDescription($value);
1050
                break;
1051
        } // switch()
1052
1053
        return $this;
1054
    }
1055
1056
    /**
1057
     * Populates the object using an array.
1058
     *
1059
     * This is particularly useful when populating an object from one of the
1060
     * request arrays (e.g. $_POST).  This method goes through the column
1061
     * names, checking to see whether a matching key exists in populated
1062
     * array. If so the setByName() method is called for that column.
1063
     *
1064
     * You can specify the key type of the array by additionally passing one
1065
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1066
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1067
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1068
     *
1069
     * @param      array  $arr     An array to populate the object from.
1070
     * @param      string $keyType The type of keys the array uses.
1071
     * @return void
1072
     */
1073 View Code Duplication
    public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME)
1074
    {
1075
        $keys = BannerImageI18nTableMap::getFieldNames($keyType);
1076
1077
        if (array_key_exists($keys[0], $arr)) {
1078
            $this->setId($arr[$keys[0]]);
1079
        }
1080
        if (array_key_exists($keys[1], $arr)) {
1081
            $this->setLocale($arr[$keys[1]]);
1082
        }
1083
        if (array_key_exists($keys[2], $arr)) {
1084
            $this->setSrc($arr[$keys[2]]);
1085
        }
1086
        if (array_key_exists($keys[3], $arr)) {
1087
            $this->setName($arr[$keys[3]]);
1088
        }
1089
        if (array_key_exists($keys[4], $arr)) {
1090
            $this->setClicks($arr[$keys[4]]);
1091
        }
1092
        if (array_key_exists($keys[5], $arr)) {
1093
            $this->setDescription($arr[$keys[5]]);
1094
        }
1095
    }
1096
1097
     /**
1098
     * Populate the current object from a string, using a given parser format
1099
     * <code>
1100
     * $book = new Book();
1101
     * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
1102
     * </code>
1103
     *
1104
     * You can specify the key type of the array by additionally passing one
1105
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1106
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1107
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1108
     *
1109
     * @param mixed $parser A AbstractParser instance,
1110
     *                       or a format name ('XML', 'YAML', 'JSON', 'CSV')
1111
     * @param string $data The source data to import from
1112
     * @param string $keyType The type of keys the array uses.
1113
     *
1114
     * @return $this|\xbanners\models\BannerImageI18n The current object, for fluid interface
1115
     */
1116 View Code Duplication
    public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME)
1117
    {
1118
        if (!$parser instanceof AbstractParser) {
1119
            $parser = AbstractParser::getParser($parser);
1120
        }
1121
1122
        $this->fromArray($parser->toArray($data), $keyType);
1123
1124
        return $this;
1125
    }
1126
1127
    /**
1128
     * Build a Criteria object containing the values of all modified columns in this object.
1129
     *
1130
     * @return Criteria The Criteria object containing all modified values.
1131
     */
1132
    public function buildCriteria()
1133
    {
1134
        $criteria = new Criteria(BannerImageI18nTableMap::DATABASE_NAME);
1135
1136
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_ID)) {
1137
            $criteria->add(BannerImageI18nTableMap::COL_ID, $this->id);
1138
        }
1139
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_LOCALE)) {
1140
            $criteria->add(BannerImageI18nTableMap::COL_LOCALE, $this->locale);
1141
        }
1142
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_SRC)) {
1143
            $criteria->add(BannerImageI18nTableMap::COL_SRC, $this->src);
1144
        }
1145
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_NAME)) {
1146
            $criteria->add(BannerImageI18nTableMap::COL_NAME, $this->name);
1147
        }
1148
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_CLICKS)) {
1149
            $criteria->add(BannerImageI18nTableMap::COL_CLICKS, $this->clicks);
1150
        }
1151
        if ($this->isColumnModified(BannerImageI18nTableMap::COL_DESCRIPTION)) {
1152
            $criteria->add(BannerImageI18nTableMap::COL_DESCRIPTION, $this->description);
1153
        }
1154
1155
        return $criteria;
1156
    }
1157
1158
    /**
1159
     * Builds a Criteria object containing the primary key for this object.
1160
     *
1161
     * Unlike buildCriteria() this method includes the primary key values regardless
1162
     * of whether or not they have been modified.
1163
     *
1164
     * @throws LogicException if no primary key is defined
1165
     *
1166
     * @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 ChildBannerImageI18nQuery.

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...
1167
     */
1168
    public function buildPkeyCriteria()
1169
    {
1170
        $criteria = ChildBannerImageI18nQuery::create();
1171
        $criteria->add(BannerImageI18nTableMap::COL_ID, $this->id);
1172
        $criteria->add(BannerImageI18nTableMap::COL_LOCALE, $this->locale);
1173
1174
        return $criteria;
1175
    }
1176
1177
    /**
1178
     * If the primary key is not null, return the hashcode of the
1179
     * primary key. Otherwise, return the hash code of the object.
1180
     *
1181
     * @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...
1182
     */
1183 View Code Duplication
    public function hashCode()
1184
    {
1185
        $validPk = null !== $this->getId() &&
1186
            null !== $this->getLocale();
1187
1188
        $validPrimaryKeyFKs = 1;
1189
        $primaryKeyFKs = [];
1190
1191
        //relation banner_image_i18n_fk_03c8df to table banner_image
1192
        if ($this->aBannerImage && $hash = spl_object_hash($this->aBannerImage)) {
1193
            $primaryKeyFKs[] = $hash;
1194
        } else {
1195
            $validPrimaryKeyFKs = false;
1196
        }
1197
1198
        if ($validPk) {
1199
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
1200
        } elseif ($validPrimaryKeyFKs) {
1201
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
1202
        }
1203
1204
        return spl_object_hash($this);
1205
    }
1206
1207
    /**
1208
     * Returns the composite primary key for this object.
1209
     * The array elements will be in same order as specified in XML.
1210
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<integer|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...
1211
     */
1212 View Code Duplication
    public function getPrimaryKey()
1213
    {
1214
        $pks = array();
1215
        $pks[0] = $this->getId();
1216
        $pks[1] = $this->getLocale();
1217
1218
        return $pks;
1219
    }
1220
1221
    /**
1222
     * Set the [composite] primary key.
1223
     *
1224
     * @param      array $keys The elements of the composite key (order must match the order in XML file).
1225
     * @return void
1226
     */
1227
    public function setPrimaryKey($keys)
1228
    {
1229
        $this->setId($keys[0]);
1230
        $this->setLocale($keys[1]);
1231
    }
1232
1233
    /**
1234
     * Returns true if the primary key for this object is null.
1235
     * @return boolean
1236
     */
1237
    public function isPrimaryKeyNull()
1238
    {
1239
        return (null === $this->getId()) && (null === $this->getLocale());
1240
    }
1241
1242
    /**
1243
     * Sets contents of passed object to values from current object.
1244
     *
1245
     * If desired, this method can also make copies of all associated (fkey referrers)
1246
     * objects.
1247
     *
1248
     * @param      object $copyObj An object of \xbanners\models\BannerImageI18n (or compatible) type.
1249
     * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1250
     * @param      boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1251
     * @throws PropelException
1252
     */
1253
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
0 ignored issues
show
Unused Code introduced by
The parameter $deepCopy is not used and could be removed.

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

Loading history...
1254
    {
1255
        $copyObj->setId($this->getId());
1256
        $copyObj->setLocale($this->getLocale());
1257
        $copyObj->setSrc($this->getSrc());
1258
        $copyObj->setName($this->getName());
1259
        $copyObj->setClicks($this->getClicks());
1260
        $copyObj->setDescription($this->getDescription());
1261
        if ($makeNew) {
1262
            $copyObj->setNew(true);
1263
        }
1264
    }
1265
1266
    /**
1267
     * Makes a copy of this object that will be inserted as a new row in table when saved.
1268
     * It creates a new object filling in the simple attributes, but skipping any primary
1269
     * keys that are defined for the table.
1270
     *
1271
     * If desired, this method can also make copies of all associated (fkey referrers)
1272
     * objects.
1273
     *
1274
     * @param  boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1275
     * @return \xbanners\models\BannerImageI18n Clone of current object.
1276
     * @throws PropelException
1277
     */
1278 View Code Duplication
    public function copy($deepCopy = false)
1279
    {
1280
        // we use get_class(), because this might be a subclass
1281
        $clazz = get_class($this);
1282
        $copyObj = new $clazz();
1283
        $this->copyInto($copyObj, $deepCopy);
1284
1285
        return $copyObj;
1286
    }
1287
1288
    /**
1289
     * Declares an association between this object and a ChildBannerImage object.
1290
     *
1291
     * @param  ChildBannerImage $v
1292
     * @return $this|\xbanners\models\BannerImageI18n The current object (for fluent API support)
1293
     * @throws PropelException
1294
     */
1295 View Code Duplication
    public function setBannerImage(ChildBannerImage $v = null)
1296
    {
1297
        if ($v === null) {
1298
            $this->setId(NULL);
1299
        } else {
1300
            $this->setId($v->getId());
1301
        }
1302
1303
        $this->aBannerImage = $v;
1304
1305
        // Add binding for other direction of this n:n relationship.
1306
        // If this object has already been added to the ChildBannerImage object, it will not be re-added.
1307
        if ($v !== null) {
1308
            $v->addBannerImageI18n($this);
0 ignored issues
show
Compatibility introduced by
$this of type object<xbanners\models\Base\BannerImageI18n> is not a sub-type of object<xbanners\models\BannerImageI18n>. It seems like you assume a child class of the class xbanners\models\Base\BannerImageI18n to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
1309
        }
1310
1311
1312
        return $this;
1313
    }
1314
1315
1316
    /**
1317
     * Get the associated ChildBannerImage object
1318
     *
1319
     * @param  ConnectionInterface $con Optional Connection object.
1320
     * @return ChildBannerImage The associated ChildBannerImage object.
1321
     * @throws PropelException
1322
     */
1323
    public function getBannerImage(ConnectionInterface $con = null)
1324
    {
1325
        if ($this->aBannerImage === null && ($this->id !== null)) {
1326
            $this->aBannerImage = ChildBannerImageQuery::create()->findPk($this->id, $con);
1327
            /* The following can be used additionally to
1328
                guarantee the related object contains a reference
1329
                to this object.  This level of coupling may, however, be
1330
                undesirable since it could result in an only partially populated collection
1331
                in the referenced object.
1332
                $this->aBannerImage->addBannerImageI18ns($this);
1333
             */
1334
        }
1335
1336
        return $this->aBannerImage;
1337
    }
1338
1339
    /**
1340
     * Clears the current object, sets all attributes to their default values and removes
1341
     * outgoing references as well as back-references (from other objects to this one. Results probably in a database
1342
     * change of those foreign objects when you call `save` there).
1343
     */
1344
    public function clear()
1345
    {
1346
        if (null !== $this->aBannerImage) {
1347
            $this->aBannerImage->removeBannerImageI18n($this);
0 ignored issues
show
Compatibility introduced by
$this of type object<xbanners\models\Base\BannerImageI18n> is not a sub-type of object<xbanners\models\BannerImageI18n>. It seems like you assume a child class of the class xbanners\models\Base\BannerImageI18n to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
1348
        }
1349
        $this->id = null;
1350
        $this->locale = null;
1351
        $this->src = null;
1352
        $this->name = null;
1353
        $this->clicks = null;
1354
        $this->description = null;
1355
        $this->alreadyInSave = false;
1356
        $this->clearAllReferences();
1357
        $this->applyDefaultValues();
1358
        $this->resetModified();
1359
        $this->setNew(true);
1360
        $this->setDeleted(false);
1361
    }
1362
1363
    /**
1364
     * Resets all references and back-references to other model objects or collections of model objects.
1365
     *
1366
     * This method is used to reset all php object references (not the actual reference in the database).
1367
     * Necessary for object serialisation.
1368
     *
1369
     * @param      boolean $deep Whether to also clear the references on all referrer objects.
1370
     */
1371
    public function clearAllReferences($deep = false)
1372
    {
1373
        if ($deep) {
1374
        } // if ($deep)
1375
1376
        $this->aBannerImage = null;
1377
    }
1378
1379
    /**
1380
     * Return the string representation of this object
1381
     *
1382
     * @return string
1383
     */
1384
    public function __toString()
1385
    {
1386
        return (string) $this->exportTo(BannerImageI18nTableMap::DEFAULT_STRING_FORMAT);
1387
    }
1388
1389
    /**
1390
     * Code to be run before persisting the object
1391
     * @param  ConnectionInterface $con
1392
     * @return boolean
1393
     */
1394
    public function preSave(ConnectionInterface $con = null)
1395
    {
1396
        if (is_callable('parent::preSave')) {
1397
            return parent::preSave($con);
1398
        }
1399
        return true;
1400
    }
1401
1402
    /**
1403
     * Code to be run after persisting the object
1404
     * @param ConnectionInterface $con
1405
     */
1406
    public function postSave(ConnectionInterface $con = null)
1407
    {
1408
        if (is_callable('parent::postSave')) {
1409
            parent::postSave($con);
1410
        }
1411
    }
1412
1413
    /**
1414
     * Code to be run before inserting to database
1415
     * @param  ConnectionInterface $con
1416
     * @return boolean
1417
     */
1418
    public function preInsert(ConnectionInterface $con = null)
1419
    {
1420
        if (is_callable('parent::preInsert')) {
1421
            return parent::preInsert($con);
1422
        }
1423
        return true;
1424
    }
1425
1426
    /**
1427
     * Code to be run after inserting to database
1428
     * @param ConnectionInterface $con
1429
     */
1430
    public function postInsert(ConnectionInterface $con = null)
1431
    {
1432
        if (is_callable('parent::postInsert')) {
1433
            parent::postInsert($con);
1434
        }
1435
    }
1436
1437
    /**
1438
     * Code to be run before updating the object in database
1439
     * @param  ConnectionInterface $con
1440
     * @return boolean
1441
     */
1442
    public function preUpdate(ConnectionInterface $con = null)
1443
    {
1444
        if (is_callable('parent::preUpdate')) {
1445
            return parent::preUpdate($con);
1446
        }
1447
        return true;
1448
    }
1449
1450
    /**
1451
     * Code to be run after updating the object in database
1452
     * @param ConnectionInterface $con
1453
     */
1454
    public function postUpdate(ConnectionInterface $con = null)
1455
    {
1456
        if (is_callable('parent::postUpdate')) {
1457
            parent::postUpdate($con);
1458
        }
1459
    }
1460
1461
    /**
1462
     * Code to be run before deleting the object in database
1463
     * @param  ConnectionInterface $con
1464
     * @return boolean
1465
     */
1466
    public function preDelete(ConnectionInterface $con = null)
1467
    {
1468
        if (is_callable('parent::preDelete')) {
1469
            return parent::preDelete($con);
1470
        }
1471
        return true;
1472
    }
1473
1474
    /**
1475
     * Code to be run after deleting the object in database
1476
     * @param ConnectionInterface $con
1477
     */
1478
    public function postDelete(ConnectionInterface $con = null)
1479
    {
1480
        if (is_callable('parent::postDelete')) {
1481
            parent::postDelete($con);
1482
        }
1483
    }
1484
1485
1486
    /**
1487
     * Derived method to catches calls to undefined methods.
1488
     *
1489
     * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
1490
     * Allows to define default __call() behavior if you overwrite __call()
1491
     *
1492
     * @param string $name
1493
     * @param mixed  $params
1494
     *
1495
     * @return array|string
1496
     */
1497 View Code Duplication
    public function __call($name, $params)
1498
    {
1499
        if (0 === strpos($name, 'get')) {
1500
            $virtualColumn = substr($name, 3);
1501
            if ($this->hasVirtualColumn($virtualColumn)) {
1502
                return $this->getVirtualColumn($virtualColumn);
1503
            }
1504
1505
            $virtualColumn = lcfirst($virtualColumn);
1506
            if ($this->hasVirtualColumn($virtualColumn)) {
1507
                return $this->getVirtualColumn($virtualColumn);
1508
            }
1509
        }
1510
1511
        if (0 === strpos($name, 'from')) {
1512
            $format = substr($name, 4);
1513
1514
            return $this->importFrom($format, reset($params));
1515
        }
1516
1517
        if (0 === strpos($name, 'to')) {
1518
            $format = substr($name, 2);
1519
            $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
1520
1521
            return $this->exportTo($format, $includeLazyLoadColumns);
1522
        }
1523
1524
        throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
1525
    }
1526
1527
}
1528