Selfprice   F
last analyzed

Complexity

Total Complexity 158

Size/Duplication

Total Lines 1239
Duplicated Lines 21.31 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 0
Metric Value
wmc 158
c 0
b 0
f 0
lcom 1
cbo 11
dl 264
loc 1239
rs 3.9999

61 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isModified() 0 4 1
A isColumnModified() 0 4 2
A getModifiedColumns() 0 4 2
A isNew() 0 4 1
A setNew() 0 4 1
A isDeleted() 0 4 1
A setDeleted() 0 4 1
A resetModified() 10 10 3
B equals() 16 16 5
A getVirtualColumns() 0 4 1
A hasVirtualColumn() 0 4 1
A getVirtualColumn() 8 8 2
A setVirtualColumn() 0 6 1
A log() 0 4 1
A exportTo() 8 8 2
A __sleep() 0 6 1
A getId() 0 4 1
A getName() 0 4 1
A getDatecreate() 0 8 3
A getDesc() 0 4 1
A setId() 0 13 3
A setName() 0 13 3
B setDatecreate() 12 12 7
A setDesc() 0 13 3
A hasOnlyDefaultValues() 0 5 1
F hydrate() 0 32 12
A ensureConsistency() 0 3 1
B reload() 29 29 6
A delete() 21 21 4
C save() 34 34 8
B doSave() 23 23 5
C doInsert() 16 63 14
A doUpdate() 0 7 1
A getByName() 7 7 1
B getByPosition() 0 20 5
B toArray() 5 30 4
A setByName() 0 6 1
B setByPosition() 0 19 5
B fromArray() 0 17 5
A importFrom() 10 10 2
B buildCriteria() 0 19 5
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
A copyInto() 0 10 2
A copy() 9 9 1
A clear() 12 12 1
A clearAllReferences() 0 6 2
A __toString() 0 4 1
A preSave() 0 4 1
A postSave() 0 4 1
A preInsert() 0 4 1
A postInsert() 0 4 1
A preUpdate() 0 4 1
A postUpdate() 0 4 1
A preDelete() 0 4 1
A postDelete() 0 4 1
C __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 Selfprice 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 Selfprice, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Selfprice\Models\Selfprice\Base;
4
5
use \DateTime;
6
use \Exception;
7
use \PDO;
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 Propel\Runtime\Util\PropelDateTime;
20
use Selfprice\Models\Selfprice\SelfpriceQuery as ChildSelfpriceQuery;
21
use Selfprice\Models\Selfprice\Map\SelfpriceTableMap;
22
23
/**
24
 * Base class that represents a row from the 'selfprice' table.
25
 *
26
 *
27
 *
28
* @package    propel.generator.Models.Selfprice.Base
29
*/
30
abstract class Selfprice implements ActiveRecordInterface
31
{
32
    /**
33
     * TableMap class name
34
     */
35
    const TABLE_MAP = '\\Selfprice\\Models\\Selfprice\\Map\\SelfpriceTableMap';
36
37
38
    /**
39
     * attribute to determine if this object has previously been saved.
40
     * @var boolean
41
     */
42
    protected $new = true;
43
44
    /**
45
     * attribute to determine whether this object has been deleted.
46
     * @var boolean
47
     */
48
    protected $deleted = false;
49
50
    /**
51
     * The columns that have been modified in current object.
52
     * Tracking modified columns allows us to only update modified columns.
53
     * @var array
54
     */
55
    protected $modifiedColumns = array();
56
57
    /**
58
     * The (virtual) columns that are added at runtime
59
     * The formatters can add supplementary columns based on a resultset
60
     * @var array
61
     */
62
    protected $virtualColumns = array();
63
64
    /**
65
     * The value for the id field.
66
     * @var        int
67
     */
68
    protected $id;
69
70
    /**
71
     * The value for the name field.
72
     * @var        string
73
     */
74
    protected $name;
75
76
    /**
77
     * The value for the datecreate field.
78
     * @var        \DateTime
79
     */
80
    protected $datecreate;
81
82
    /**
83
     * The value for the desc field.
84
     * @var        string
85
     */
86
    protected $desc;
87
88
    /**
89
     * Flag to prevent endless save loop, if this object is referenced
90
     * by another object which falls in this transaction.
91
     *
92
     * @var boolean
93
     */
94
    protected $alreadyInSave = false;
95
96
    /**
97
     * Initializes internal state of Selfprice\Models\Selfprice\Base\Selfprice object.
98
     */
99
    public function __construct()
100
    {
101
    }
102
103
    /**
104
     * Returns whether the object has been modified.
105
     *
106
     * @return boolean True if the object has been modified.
107
     */
108
    public function isModified()
109
    {
110
        return !!$this->modifiedColumns;
111
    }
112
113
    /**
114
     * Has specified column been modified?
115
     *
116
     * @param  string  $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID
117
     * @return boolean True if $col has been modified.
118
     */
119
    public function isColumnModified($col)
120
    {
121
        return $this->modifiedColumns && isset($this->modifiedColumns[$col]);
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->modifiedColumns of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
122
    }
123
124
    /**
125
     * Get the columns that have been modified in this object.
126
     * @return array A unique list of the modified column names for this object.
127
     */
128
    public function getModifiedColumns()
129
    {
130
        return $this->modifiedColumns ? array_keys($this->modifiedColumns) : [];
131
    }
132
133
    /**
134
     * Returns whether the object has ever been saved.  This will
135
     * be false, if the object was retrieved from storage or was created
136
     * and then saved.
137
     *
138
     * @return boolean true, if the object has never been persisted.
139
     */
140
    public function isNew()
141
    {
142
        return $this->new;
143
    }
144
145
    /**
146
     * Setter for the isNew attribute.  This method will be called
147
     * by Propel-generated children and objects.
148
     *
149
     * @param boolean $b the state of the object.
150
     */
151
    public function setNew($b)
152
    {
153
        $this->new = (boolean) $b;
154
    }
155
156
    /**
157
     * Whether this object has been deleted.
158
     * @return boolean The deleted state of this object.
159
     */
160
    public function isDeleted()
161
    {
162
        return $this->deleted;
163
    }
164
165
    /**
166
     * Specify whether this object has been deleted.
167
     * @param  boolean $b The deleted state of this object.
168
     * @return void
169
     */
170
    public function setDeleted($b)
171
    {
172
        $this->deleted = (boolean) $b;
173
    }
174
175
    /**
176
     * Sets the modified state for the object to be false.
177
     * @param  string $col If supplied, only the specified column is reset.
178
     * @return void
179
     */
180 View Code Duplication
    public function resetModified($col = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
181
    {
182
        if (null !== $col) {
183
            if (isset($this->modifiedColumns[$col])) {
184
                unset($this->modifiedColumns[$col]);
185
            }
186
        } else {
187
            $this->modifiedColumns = array();
188
        }
189
    }
190
191
    /**
192
     * Compares this with another <code>Selfprice</code> instance.  If
193
     * <code>obj</code> is an instance of <code>Selfprice</code>, delegates to
194
     * <code>equals(Selfprice)</code>.  Otherwise, returns <code>false</code>.
195
     *
196
     * @param  mixed   $obj The object to compare to.
197
     * @return boolean Whether equal to the object specified.
198
     */
199 View Code Duplication
    public function equals($obj)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
200
    {
201
        if (!$obj instanceof static) {
202
            return false;
203
        }
204
205
        if ($this === $obj) {
206
            return true;
207
        }
208
209
        if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) {
210
            return false;
211
        }
212
213
        return $this->getPrimaryKey() === $obj->getPrimaryKey();
214
    }
215
216
    /**
217
     * Get the associative array of the virtual columns in this object
218
     *
219
     * @return array
220
     */
221
    public function getVirtualColumns()
222
    {
223
        return $this->virtualColumns;
224
    }
225
226
    /**
227
     * Checks the existence of a virtual column in this object
228
     *
229
     * @param  string  $name The virtual column name
230
     * @return boolean
231
     */
232
    public function hasVirtualColumn($name)
233
    {
234
        return array_key_exists($name, $this->virtualColumns);
235
    }
236
237
    /**
238
     * Get the value of a virtual column in this object
239
     *
240
     * @param  string $name The virtual column name
241
     * @return mixed
242
     *
243
     * @throws PropelException
244
     */
245 View Code Duplication
    public function getVirtualColumn($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
246
    {
247
        if (!$this->hasVirtualColumn($name)) {
248
            throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name));
249
        }
250
251
        return $this->virtualColumns[$name];
252
    }
253
254
    /**
255
     * Set the value of a virtual column in this object
256
     *
257
     * @param string $name  The virtual column name
258
     * @param mixed  $value The value to give to the virtual column
259
     *
260
     * @return $this|Selfprice The current object, for fluid interface
261
     */
262
    public function setVirtualColumn($name, $value)
263
    {
264
        $this->virtualColumns[$name] = $value;
265
266
        return $this;
267
    }
268
269
    /**
270
     * Logs a message using Propel::log().
271
     *
272
     * @param  string  $msg
273
     * @param  int     $priority One of the Propel::LOG_* logging levels
274
     * @return boolean
275
     */
276
    protected function log($msg, $priority = Propel::LOG_INFO)
277
    {
278
        return Propel::log(get_class($this) . ': ' . $msg, $priority);
279
    }
280
281
    /**
282
     * Export the current object properties to a string, using a given parser format
283
     * <code>
284
     * $book = BookQuery::create()->findPk(9012);
285
     * echo $book->exportTo('JSON');
286
     *  => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
287
     * </code>
288
     *
289
     * @param  mixed   $parser                 A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
290
     * @param  boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
291
     * @return string  The exported data
292
     */
293 View Code Duplication
    public function exportTo($parser, $includeLazyLoadColumns = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
294
    {
295
        if (!$parser instanceof AbstractParser) {
296
            $parser = AbstractParser::getParser($parser);
297
        }
298
299
        return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true));
0 ignored issues
show
Unused Code introduced by
The call to Selfprice::toArray() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Bug introduced by
It seems like $this->toArray(\Propel\R...Columns, array(), true) targeting Selfprice\Models\Selfpri...se\Selfprice::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...
300
    }
301
302
    /**
303
     * Clean up internal collections prior to serializing
304
     * Avoids recursive loops that turn into segmentation faults when serializing
305
     */
306
    public function __sleep()
307
    {
308
        $this->clearAllReferences();
0 ignored issues
show
Unused Code introduced by
The call to the method Selfprice\Models\Selfpri...e::clearAllReferences() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
309
310
        return array_keys(get_object_vars($this));
311
    }
312
313
    /**
314
     * Get the [id] column value.
315
     *
316
     * @return int
317
     */
318
    public function getId()
319
    {
320
        return $this->id;
321
    }
322
323
    /**
324
     * Get the [name] column value.
325
     *
326
     * @return string
327
     */
328
    public function getName()
329
    {
330
        return $this->name;
331
    }
332
333
    /**
334
     * Get the [optionally formatted] temporal [datecreate] column value.
335
     *
336
     *
337
     * @param      string $format The date/time format string (either date()-style or strftime()-style).
338
     *                            If format is NULL, then the raw DateTime object will be returned.
339
     *
340
     * @return string|DateTime Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00
341
     *
342
     * @throws PropelException - if unable to parse/validate the date/time value.
343
     */
344
    public function getDatecreate($format = NULL)
345
    {
346
        if ($format === null) {
347
            return $this->datecreate;
348
        } else {
349
            return $this->datecreate instanceof \DateTime ? $this->datecreate->format($format) : null;
350
        }
351
    }
352
353
    /**
354
     * Get the [desc] column value.
355
     *
356
     * @return string
357
     */
358
    public function getDesc()
359
    {
360
        return $this->desc;
361
    }
362
363
    /**
364
     * Set the value of [id] column.
365
     *
366
     * @param int $v new value
367
     * @return $this|\Selfprice\Models\Selfprice\Selfprice The current object (for fluent API support)
368
     */
369
    public function setId($v)
370
    {
371
        if ($v !== null) {
372
            $v = (int) $v;
373
        }
374
375
        if ($this->id !== $v) {
376
            $this->id = $v;
377
            $this->modifiedColumns[SelfpriceTableMap::COL_ID] = true;
378
        }
379
380
        return $this;
381
    } // setId()
382
383
    /**
384
     * Set the value of [name] column.
385
     *
386
     * @param string $v new value
387
     * @return $this|\Selfprice\Models\Selfprice\Selfprice The current object (for fluent API support)
388
     */
389
    public function setName($v)
390
    {
391
        if ($v !== null) {
392
            $v = (string) $v;
393
        }
394
395
        if ($this->name !== $v) {
396
            $this->name = $v;
397
            $this->modifiedColumns[SelfpriceTableMap::COL_NAME] = true;
398
        }
399
400
        return $this;
401
    } // setName()
402
403
    /**
404
     * Sets the value of [datecreate] column to a normalized version of the date/time value specified.
405
     *
406
     * @param  mixed $v string, integer (timestamp), or \DateTime value.
407
     *               Empty strings are treated as NULL.
408
     * @return $this|\Selfprice\Models\Selfprice\Selfprice The current object (for fluent API support)
409
     */
410 View Code Duplication
    public function setDatecreate($v)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
411
    {
412
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
413
        if ($this->datecreate !== null || $dt !== null) {
414
            if ($this->datecreate === null || $dt === null || $dt->format("Y-m-d H:i:s") !== $this->datecreate->format("Y-m-d H:i:s")) {
415
                $this->datecreate = $dt === null ? null : clone $dt;
0 ignored issues
show
Documentation Bug introduced by
It seems like $dt === null ? null : clone $dt can also be of type false. However, the property $datecreate is declared as type object<DateTime>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
416
                $this->modifiedColumns[SelfpriceTableMap::COL_DATECREATE] = true;
417
            }
418
        } // if either are not null
419
420
        return $this;
421
    } // setDatecreate()
422
423
    /**
424
     * Set the value of [desc] column.
425
     *
426
     * @param string $v new value
427
     * @return $this|\Selfprice\Models\Selfprice\Selfprice The current object (for fluent API support)
428
     */
429
    public function setDesc($v)
430
    {
431
        if ($v !== null) {
432
            $v = (string) $v;
433
        }
434
435
        if ($this->desc !== $v) {
436
            $this->desc = $v;
437
            $this->modifiedColumns[SelfpriceTableMap::COL_DESC] = true;
438
        }
439
440
        return $this;
441
    } // setDesc()
442
443
    /**
444
     * Indicates whether the columns in this object are only set to default values.
445
     *
446
     * This method can be used in conjunction with isModified() to indicate whether an object is both
447
     * modified _and_ has some values set which are non-default.
448
     *
449
     * @return boolean Whether the columns in this object are only been set with default values.
450
     */
451
    public function hasOnlyDefaultValues()
452
    {
453
        // otherwise, everything was equal, so return TRUE
454
        return true;
455
    } // hasOnlyDefaultValues()
456
457
    /**
458
     * Hydrates (populates) the object variables with values from the database resultset.
459
     *
460
     * An offset (0-based "start column") is specified so that objects can be hydrated
461
     * with a subset of the columns in the resultset rows.  This is needed, for example,
462
     * for results of JOIN queries where the resultset row includes columns from two or
463
     * more tables.
464
     *
465
     * @param array   $row       The row returned by DataFetcher->fetch().
466
     * @param int     $startcol  0-based offset column which indicates which restultset column to start with.
467
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
468
     * @param string  $indexType The index type of $row. Mostly DataFetcher->getIndexType().
469
                                  One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
470
     *                            TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
471
     *
472
     * @return int             next starting column
473
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
474
     */
475
    public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM)
476
    {
477
        try {
478
479
            $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : SelfpriceTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
480
            $this->id = (null !== $col) ? (int) $col : null;
481
482
            $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : SelfpriceTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)];
483
            $this->name = (null !== $col) ? (string) $col : null;
484
485
            $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : SelfpriceTableMap::translateFieldName('Datecreate', TableMap::TYPE_PHPNAME, $indexType)];
486
            if ($col === '0000-00-00 00:00:00') {
487
                $col = null;
488
            }
489
            $this->datecreate = (null !== $col) ? PropelDateTime::newInstance($col, null, 'DateTime') : null;
490
491
            $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : SelfpriceTableMap::translateFieldName('Desc', TableMap::TYPE_PHPNAME, $indexType)];
492
            $this->desc = (null !== $col) ? (string) $col : null;
493
            $this->resetModified();
494
495
            $this->setNew(false);
496
497
            if ($rehydrate) {
498
                $this->ensureConsistency();
499
            }
500
501
            return $startcol + 4; // 4 = SelfpriceTableMap::NUM_HYDRATE_COLUMNS.
502
503
        } catch (Exception $e) {
504
            throw new PropelException(sprintf('Error populating %s object', '\\Selfprice\\Models\\Selfprice\\Selfprice'), 0, $e);
505
        }
506
    }
507
508
    /**
509
     * Checks and repairs the internal consistency of the object.
510
     *
511
     * This method is executed after an already-instantiated object is re-hydrated
512
     * from the database.  It exists to check any foreign keys to make sure that
513
     * the objects related to the current object are correct based on foreign key.
514
     *
515
     * You can override this method in the stub class, but you should always invoke
516
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
517
     * in case your model changes.
518
     *
519
     * @throws PropelException
520
     */
521
    public function ensureConsistency()
522
    {
523
    } // ensureConsistency
524
525
    /**
526
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
527
     *
528
     * This will only work if the object has been saved and has a valid primary key set.
529
     *
530
     * @param      boolean $deep (optional) Whether to also de-associated any related objects.
531
     * @param      ConnectionInterface $con (optional) The ConnectionInterface connection to use.
532
     * @return void
533
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
534
     */
535 View Code Duplication
    public function reload($deep = false, ConnectionInterface $con = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
536
    {
537
        if ($this->isDeleted()) {
538
            throw new PropelException("Cannot reload a deleted object.");
539
        }
540
541
        if ($this->isNew()) {
542
            throw new PropelException("Cannot reload an unsaved object.");
543
        }
544
545
        if ($con === null) {
546
            $con = Propel::getServiceContainer()->getReadConnection(SelfpriceTableMap::DATABASE_NAME);
547
        }
548
549
        // We don't need to alter the object instance pool; we're just modifying this instance
550
        // already in the pool.
551
552
        $dataFetcher = ChildSelfpriceQuery::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: Core\Models\Task\Base\TaskQuery, Core\Models\Task\TaskQuery, Core\Models\User\Base\UserQuery, Core\Models\User\UserQuery, Propel\Runtime\ActiveQuery\ModelCriteria, Selfprice\Models\Selfprice\Base\SelfpriceQuery, Selfprice\Models\Selfprice\SelfpriceQuery. 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...
553
        $row = $dataFetcher->fetch();
554
        $dataFetcher->close();
555
        if (!$row) {
556
            throw new PropelException('Cannot find matching row in the database to reload object values.');
557
        }
558
        $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate
559
560
        if ($deep) {  // also de-associate any related objects?
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
561
562
        } // if (deep)
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
563
    }
564
565
    /**
566
     * Removes this object from datastore and sets delete attribute.
567
     *
568
     * @param      ConnectionInterface $con
569
     * @return void
570
     * @throws PropelException
571
     * @see Selfprice::setDeleted()
572
     * @see Selfprice::isDeleted()
573
     */
574 View Code Duplication
    public function delete(ConnectionInterface $con = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
575
    {
576
        if ($this->isDeleted()) {
577
            throw new PropelException("This object has already been deleted.");
578
        }
579
580
        if ($con === null) {
581
            $con = Propel::getServiceContainer()->getWriteConnection(SelfpriceTableMap::DATABASE_NAME);
582
        }
583
584
        $con->transaction(function () use ($con) {
585
            $deleteQuery = ChildSelfpriceQuery::create()
586
                ->filterByPrimaryKey($this->getPrimaryKey());
587
            $ret = $this->preDelete($con);
588
            if ($ret) {
589
                $deleteQuery->delete($con);
590
                $this->postDelete($con);
591
                $this->setDeleted(true);
592
            }
593
        });
594
    }
595
596
    /**
597
     * Persists this object to the database.
598
     *
599
     * If the object is new, it inserts it; otherwise an update is performed.
600
     * All modified related objects will also be persisted in the doSave()
601
     * method.  This method wraps all precipitate database operations in a
602
     * single transaction.
603
     *
604
     * @param      ConnectionInterface $con
605
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
606
     * @throws PropelException
607
     * @see doSave()
608
     */
609 View Code Duplication
    public function save(ConnectionInterface $con = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
610
    {
611
        if ($this->isDeleted()) {
612
            throw new PropelException("You cannot save an object that has been deleted.");
613
        }
614
615
        if ($con === null) {
616
            $con = Propel::getServiceContainer()->getWriteConnection(SelfpriceTableMap::DATABASE_NAME);
617
        }
618
619
        return $con->transaction(function () use ($con) {
620
            $isInsert = $this->isNew();
621
            $ret = $this->preSave($con);
622
            if ($isInsert) {
623
                $ret = $ret && $this->preInsert($con);
624
            } else {
625
                $ret = $ret && $this->preUpdate($con);
626
            }
627
            if ($ret) {
628
                $affectedRows = $this->doSave($con);
629
                if ($isInsert) {
630
                    $this->postInsert($con);
631
                } else {
632
                    $this->postUpdate($con);
633
                }
634
                $this->postSave($con);
635
                SelfpriceTableMap::addInstanceToPool($this);
636
            } else {
637
                $affectedRows = 0;
638
            }
639
640
            return $affectedRows;
641
        });
642
    }
643
644
    /**
645
     * Performs the work of inserting or updating the row in the database.
646
     *
647
     * If the object is new, it inserts it; otherwise an update is performed.
648
     * All related objects are also updated in this method.
649
     *
650
     * @param      ConnectionInterface $con
651
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
652
     * @throws PropelException
653
     * @see save()
654
     */
655 View Code Duplication
    protected function doSave(ConnectionInterface $con)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
656
    {
657
        $affectedRows = 0; // initialize var to track total num of affected rows
658
        if (!$this->alreadyInSave) {
659
            $this->alreadyInSave = true;
660
661
            if ($this->isNew() || $this->isModified()) {
662
                // persist changes
663
                if ($this->isNew()) {
664
                    $this->doInsert($con);
665
                    $affectedRows += 1;
666
                } else {
667
                    $affectedRows += $this->doUpdate($con);
668
                }
669
                $this->resetModified();
670
            }
671
672
            $this->alreadyInSave = false;
673
674
        }
675
676
        return $affectedRows;
677
    } // doSave()
678
679
    /**
680
     * Insert the row in the database.
681
     *
682
     * @param      ConnectionInterface $con
683
     *
684
     * @throws PropelException
685
     * @see doSave()
686
     */
687
    protected function doInsert(ConnectionInterface $con)
688
    {
689
        $modifiedColumns = array();
690
        $index = 0;
691
692
        $this->modifiedColumns[SelfpriceTableMap::COL_ID] = true;
693
        if (null !== $this->id) {
694
            throw new PropelException('Cannot insert a value for auto-increment primary key (' . SelfpriceTableMap::COL_ID . ')');
695
        }
696
697
         // check the columns in natural order for more readable SQL queries
698
        if ($this->isColumnModified(SelfpriceTableMap::COL_ID)) {
699
            $modifiedColumns[':p' . $index++]  = 'id';
700
        }
701
        if ($this->isColumnModified(SelfpriceTableMap::COL_NAME)) {
702
            $modifiedColumns[':p' . $index++]  = 'name';
703
        }
704
        if ($this->isColumnModified(SelfpriceTableMap::COL_DATECREATE)) {
705
            $modifiedColumns[':p' . $index++]  = 'datecreate';
706
        }
707
        if ($this->isColumnModified(SelfpriceTableMap::COL_DESC)) {
708
            $modifiedColumns[':p' . $index++]  = 'desc';
709
        }
710
711
        $sql = sprintf(
712
            'INSERT INTO selfprice (%s) VALUES (%s)',
713
            implode(', ', $modifiedColumns),
714
            implode(', ', array_keys($modifiedColumns))
715
        );
716
717
        try {
718
            $stmt = $con->prepare($sql);
719 View Code Duplication
            foreach ($modifiedColumns as $identifier => $columnName) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
720
                switch ($columnName) {
721
                    case 'id':
722
                        $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
723
                        break;
724
                    case 'name':
725
                        $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR);
726
                        break;
727
                    case 'datecreate':
728
                        $stmt->bindValue($identifier, $this->datecreate ? $this->datecreate->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
729
                        break;
730
                    case 'desc':
731
                        $stmt->bindValue($identifier, $this->desc, PDO::PARAM_STR);
732
                        break;
733
                }
734
            }
735
            $stmt->execute();
736
        } catch (Exception $e) {
737
            Propel::log($e->getMessage(), Propel::LOG_ERR);
738
            throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
739
        }
740
741
        try {
742
            $pk = $con->lastInsertId();
743
        } catch (Exception $e) {
744
            throw new PropelException('Unable to get autoincrement id.', 0, $e);
745
        }
746
        $this->setId($pk);
747
748
        $this->setNew(false);
749
    }
750
751
    /**
752
     * Update the row in the database.
753
     *
754
     * @param      ConnectionInterface $con
755
     *
756
     * @return Integer Number of updated rows
757
     * @see doSave()
758
     */
759
    protected function doUpdate(ConnectionInterface $con)
760
    {
761
        $selectCriteria = $this->buildPkeyCriteria();
762
        $valuesCriteria = $this->buildCriteria();
763
764
        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...
765
    }
766
767
    /**
768
     * Retrieves a field from the object by name passed in as a string.
769
     *
770
     * @param      string $name name
771
     * @param      string $type The type of fieldname the $name is of:
772
     *                     one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
773
     *                     TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
774
     *                     Defaults to TableMap::TYPE_PHPNAME.
775
     * @return mixed Value of field.
776
     */
777 View Code Duplication
    public function getByName($name, $type = TableMap::TYPE_PHPNAME)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
778
    {
779
        $pos = SelfpriceTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
780
        $field = $this->getByPosition($pos);
781
782
        return $field;
783
    }
784
785
    /**
786
     * Retrieves a field from the object by Position as specified in the xml schema.
787
     * Zero-based.
788
     *
789
     * @param      int $pos position in xml schema
790
     * @return mixed Value of field at $pos
791
     */
792
    public function getByPosition($pos)
793
    {
794
        switch ($pos) {
795
            case 0:
796
                return $this->getId();
797
                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...
798
            case 1:
799
                return $this->getName();
800
                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...
801
            case 2:
802
                return $this->getDatecreate();
803
                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...
804
            case 3:
805
                return $this->getDesc();
806
                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...
807
            default:
808
                return null;
809
                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...
810
        } // switch()
811
    }
812
813
    /**
814
     * Exports the object as an array.
815
     *
816
     * You can specify the key type of the array by passing one of the class
817
     * type constants.
818
     *
819
     * @param     string  $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
820
     *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
821
     *                    Defaults to TableMap::TYPE_PHPNAME.
822
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
823
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
824
     *
825
     * @return array an associative array containing the field names (as keys) and field values
826
     */
827
    public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
0 ignored issues
show
Unused Code introduced by
The parameter $includeLazyLoadColumns 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...
828
    {
829
830
        if (isset($alreadyDumpedObjects['Selfprice'][$this->hashCode()])) {
831
            return '*RECURSION*';
832
        }
833
        $alreadyDumpedObjects['Selfprice'][$this->hashCode()] = true;
834
        $keys = SelfpriceTableMap::getFieldNames($keyType);
835
        $result = array(
836
            $keys[0] => $this->getId(),
837
            $keys[1] => $this->getName(),
838
            $keys[2] => $this->getDatecreate(),
839
            $keys[3] => $this->getDesc(),
840
        );
841
842
        $utc = new \DateTimeZone('utc');
843 View Code Duplication
        if ($result[$keys[2]] instanceof \DateTime) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
844
            // When changing timezone we don't want to change existing instances
845
            $dateTime = clone $result[$keys[2]];
846
            $result[$keys[2]] = $dateTime->setTimezone($utc)->format('Y-m-d\TH:i:s\Z');
847
        }
848
849
        $virtualColumns = $this->virtualColumns;
850
        foreach ($virtualColumns as $key => $virtualColumn) {
851
            $result[$key] = $virtualColumn;
852
        }
853
854
855
        return $result;
856
    }
857
858
    /**
859
     * Sets a field from the object by name passed in as a string.
860
     *
861
     * @param  string $name
862
     * @param  mixed  $value field value
863
     * @param  string $type The type of fieldname the $name is of:
864
     *                one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
865
     *                TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
866
     *                Defaults to TableMap::TYPE_PHPNAME.
867
     * @return $this|\Selfprice\Models\Selfprice\Selfprice
868
     */
869
    public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME)
870
    {
871
        $pos = SelfpriceTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
872
873
        return $this->setByPosition($pos, $value);
874
    }
875
876
    /**
877
     * Sets a field from the object by Position as specified in the xml schema.
878
     * Zero-based.
879
     *
880
     * @param  int $pos position in xml schema
881
     * @param  mixed $value field value
882
     * @return $this|\Selfprice\Models\Selfprice\Selfprice
883
     */
884
    public function setByPosition($pos, $value)
885
    {
886
        switch ($pos) {
887
            case 0:
888
                $this->setId($value);
889
                break;
890
            case 1:
891
                $this->setName($value);
892
                break;
893
            case 2:
894
                $this->setDatecreate($value);
895
                break;
896
            case 3:
897
                $this->setDesc($value);
898
                break;
899
        } // switch()
900
901
        return $this;
902
    }
903
904
    /**
905
     * Populates the object using an array.
906
     *
907
     * This is particularly useful when populating an object from one of the
908
     * request arrays (e.g. $_POST).  This method goes through the column
909
     * names, checking to see whether a matching key exists in populated
910
     * array. If so the setByName() method is called for that column.
911
     *
912
     * You can specify the key type of the array by additionally passing one
913
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
914
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
915
     * The default key type is the column's TableMap::TYPE_PHPNAME.
916
     *
917
     * @param      array  $arr     An array to populate the object from.
918
     * @param      string $keyType The type of keys the array uses.
919
     * @return void
920
     */
921
    public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME)
922
    {
923
        $keys = SelfpriceTableMap::getFieldNames($keyType);
924
925
        if (array_key_exists($keys[0], $arr)) {
926
            $this->setId($arr[$keys[0]]);
927
        }
928
        if (array_key_exists($keys[1], $arr)) {
929
            $this->setName($arr[$keys[1]]);
930
        }
931
        if (array_key_exists($keys[2], $arr)) {
932
            $this->setDatecreate($arr[$keys[2]]);
933
        }
934
        if (array_key_exists($keys[3], $arr)) {
935
            $this->setDesc($arr[$keys[3]]);
936
        }
937
    }
938
939
     /**
940
     * Populate the current object from a string, using a given parser format
941
     * <code>
942
     * $book = new Book();
943
     * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
944
     * </code>
945
     *
946
     * You can specify the key type of the array by additionally passing one
947
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
948
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
949
     * The default key type is the column's TableMap::TYPE_PHPNAME.
950
     *
951
     * @param mixed $parser A AbstractParser instance,
952
     *                       or a format name ('XML', 'YAML', 'JSON', 'CSV')
953
     * @param string $data The source data to import from
954
     * @param string $keyType The type of keys the array uses.
955
     *
956
     * @return $this|\Selfprice\Models\Selfprice\Selfprice The current object, for fluid interface
957
     */
958 View Code Duplication
    public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
959
    {
960
        if (!$parser instanceof AbstractParser) {
961
            $parser = AbstractParser::getParser($parser);
962
        }
963
964
        $this->fromArray($parser->toArray($data), $keyType);
965
966
        return $this;
967
    }
968
969
    /**
970
     * Build a Criteria object containing the values of all modified columns in this object.
971
     *
972
     * @return Criteria The Criteria object containing all modified values.
973
     */
974
    public function buildCriteria()
975
    {
976
        $criteria = new Criteria(SelfpriceTableMap::DATABASE_NAME);
977
978
        if ($this->isColumnModified(SelfpriceTableMap::COL_ID)) {
979
            $criteria->add(SelfpriceTableMap::COL_ID, $this->id);
980
        }
981
        if ($this->isColumnModified(SelfpriceTableMap::COL_NAME)) {
982
            $criteria->add(SelfpriceTableMap::COL_NAME, $this->name);
983
        }
984
        if ($this->isColumnModified(SelfpriceTableMap::COL_DATECREATE)) {
985
            $criteria->add(SelfpriceTableMap::COL_DATECREATE, $this->datecreate);
986
        }
987
        if ($this->isColumnModified(SelfpriceTableMap::COL_DESC)) {
988
            $criteria->add(SelfpriceTableMap::COL_DESC, $this->desc);
989
        }
990
991
        return $criteria;
992
    }
993
994
    /**
995
     * Builds a Criteria object containing the primary key for this object.
996
     *
997
     * Unlike buildCriteria() this method includes the primary key values regardless
998
     * of whether or not they have been modified.
999
     *
1000
     * @throws LogicException if no primary key is defined
1001
     *
1002
     * @return Criteria The Criteria object containing value(s) for primary key(s).
1003
     */
1004
    public function buildPkeyCriteria()
1005
    {
1006
        $criteria = ChildSelfpriceQuery::create();
1007
        $criteria->add(SelfpriceTableMap::COL_ID, $this->id);
1008
1009
        return $criteria;
1010
    }
1011
1012
    /**
1013
     * If the primary key is not null, return the hashcode of the
1014
     * primary key. Otherwise, return the hash code of the object.
1015
     *
1016
     * @return int Hashcode
1017
     */
1018 View Code Duplication
    public function hashCode()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1019
    {
1020
        $validPk = null !== $this->getId();
1021
1022
        $validPrimaryKeyFKs = 0;
1023
        $primaryKeyFKs = [];
1024
1025
        if ($validPk) {
1026
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
1027
        } elseif ($validPrimaryKeyFKs) {
1028
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
1029
        }
1030
1031
        return spl_object_hash($this);
1032
    }
1033
1034
    /**
1035
     * Returns the primary key for this object (row).
1036
     * @return int
1037
     */
1038
    public function getPrimaryKey()
1039
    {
1040
        return $this->getId();
1041
    }
1042
1043
    /**
1044
     * Generic method to set the primary key (id column).
1045
     *
1046
     * @param       int $key Primary key.
1047
     * @return void
1048
     */
1049
    public function setPrimaryKey($key)
1050
    {
1051
        $this->setId($key);
1052
    }
1053
1054
    /**
1055
     * Returns true if the primary key for this object is null.
1056
     * @return boolean
1057
     */
1058
    public function isPrimaryKeyNull()
1059
    {
1060
        return null === $this->getId();
1061
    }
1062
1063
    /**
1064
     * Sets contents of passed object to values from current object.
1065
     *
1066
     * If desired, this method can also make copies of all associated (fkey referrers)
1067
     * objects.
1068
     *
1069
     * @param      object $copyObj An object of \Selfprice\Models\Selfprice\Selfprice (or compatible) type.
1070
     * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1071
     * @param      boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1072
     * @throws PropelException
1073
     */
1074
    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...
1075
    {
1076
        $copyObj->setName($this->getName());
1077
        $copyObj->setDatecreate($this->getDatecreate());
1078
        $copyObj->setDesc($this->getDesc());
1079
        if ($makeNew) {
1080
            $copyObj->setNew(true);
1081
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1082
        }
1083
    }
1084
1085
    /**
1086
     * Makes a copy of this object that will be inserted as a new row in table when saved.
1087
     * It creates a new object filling in the simple attributes, but skipping any primary
1088
     * keys that are defined for the table.
1089
     *
1090
     * If desired, this method can also make copies of all associated (fkey referrers)
1091
     * objects.
1092
     *
1093
     * @param  boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1094
     * @return \Selfprice\Models\Selfprice\Selfprice Clone of current object.
1095
     * @throws PropelException
1096
     */
1097 View Code Duplication
    public function copy($deepCopy = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1098
    {
1099
        // we use get_class(), because this might be a subclass
1100
        $clazz = get_class($this);
1101
        $copyObj = new $clazz();
1102
        $this->copyInto($copyObj, $deepCopy);
1103
1104
        return $copyObj;
1105
    }
1106
1107
    /**
1108
     * Clears the current object, sets all attributes to their default values and removes
1109
     * outgoing references as well as back-references (from other objects to this one. Results probably in a database
1110
     * change of those foreign objects when you call `save` there).
1111
     */
1112 View Code Duplication
    public function clear()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1113
    {
1114
        $this->id = null;
1115
        $this->name = null;
1116
        $this->datecreate = null;
1117
        $this->desc = null;
1118
        $this->alreadyInSave = false;
1119
        $this->clearAllReferences();
0 ignored issues
show
Unused Code introduced by
The call to the method Selfprice\Models\Selfpri...e::clearAllReferences() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
1120
        $this->resetModified();
1121
        $this->setNew(true);
1122
        $this->setDeleted(false);
1123
    }
1124
1125
    /**
1126
     * Resets all references and back-references to other model objects or collections of model objects.
1127
     *
1128
     * This method is used to reset all php object references (not the actual reference in the database).
1129
     * Necessary for object serialisation.
1130
     *
1131
     * @param      boolean $deep Whether to also clear the references on all referrer objects.
1132
     */
1133
    public function clearAllReferences($deep = false)
1134
    {
1135
        if ($deep) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
1136
        } // if ($deep)
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1137
1138
    }
1139
1140
    /**
1141
     * Return the string representation of this object
1142
     *
1143
     * @return string
1144
     */
1145
    public function __toString()
1146
    {
1147
        return (string) $this->exportTo(SelfpriceTableMap::DEFAULT_STRING_FORMAT);
1148
    }
1149
1150
    /**
1151
     * Code to be run before persisting the object
1152
     * @param  ConnectionInterface $con
1153
     * @return boolean
1154
     */
1155
    public function preSave(ConnectionInterface $con = null)
0 ignored issues
show
Unused Code introduced by
The parameter $con 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...
1156
    {
1157
        return true;
1158
    }
1159
1160
    /**
1161
     * Code to be run after persisting the object
1162
     * @param ConnectionInterface $con
1163
     */
1164
    public function postSave(ConnectionInterface $con = null)
0 ignored issues
show
Unused Code introduced by
The parameter $con 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...
1165
    {
1166
1167
    }
1168
1169
    /**
1170
     * Code to be run before inserting to database
1171
     * @param  ConnectionInterface $con
1172
     * @return boolean
1173
     */
1174
    public function preInsert(ConnectionInterface $con = null)
0 ignored issues
show
Unused Code introduced by
The parameter $con 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...
1175
    {
1176
        return true;
1177
    }
1178
1179
    /**
1180
     * Code to be run after inserting to database
1181
     * @param ConnectionInterface $con
1182
     */
1183
    public function postInsert(ConnectionInterface $con = null)
0 ignored issues
show
Unused Code introduced by
The parameter $con 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...
1184
    {
1185
1186
    }
1187
1188
    /**
1189
     * Code to be run before updating the object in database
1190
     * @param  ConnectionInterface $con
1191
     * @return boolean
1192
     */
1193
    public function preUpdate(ConnectionInterface $con = null)
0 ignored issues
show
Unused Code introduced by
The parameter $con 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...
1194
    {
1195
        return true;
1196
    }
1197
1198
    /**
1199
     * Code to be run after updating the object in database
1200
     * @param ConnectionInterface $con
1201
     */
1202
    public function postUpdate(ConnectionInterface $con = null)
0 ignored issues
show
Unused Code introduced by
The parameter $con 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...
1203
    {
1204
1205
    }
1206
1207
    /**
1208
     * Code to be run before deleting the object in database
1209
     * @param  ConnectionInterface $con
1210
     * @return boolean
1211
     */
1212
    public function preDelete(ConnectionInterface $con = null)
0 ignored issues
show
Unused Code introduced by
The parameter $con 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...
1213
    {
1214
        return true;
1215
    }
1216
1217
    /**
1218
     * Code to be run after deleting the object in database
1219
     * @param ConnectionInterface $con
1220
     */
1221
    public function postDelete(ConnectionInterface $con = null)
0 ignored issues
show
Unused Code introduced by
The parameter $con 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...
1222
    {
1223
1224
    }
1225
1226
1227
    /**
1228
     * Derived method to catches calls to undefined methods.
1229
     *
1230
     * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
1231
     * Allows to define default __call() behavior if you overwrite __call()
1232
     *
1233
     * @param string $name
1234
     * @param mixed  $params
1235
     *
1236
     * @return array|string
1237
     */
1238 View Code Duplication
    public function __call($name, $params)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1239
    {
1240
        if (0 === strpos($name, 'get')) {
1241
            $virtualColumn = substr($name, 3);
1242
            if ($this->hasVirtualColumn($virtualColumn)) {
1243
                return $this->getVirtualColumn($virtualColumn);
1244
            }
1245
1246
            $virtualColumn = lcfirst($virtualColumn);
1247
            if ($this->hasVirtualColumn($virtualColumn)) {
1248
                return $this->getVirtualColumn($virtualColumn);
1249
            }
1250
        }
1251
1252
        if (0 === strpos($name, 'from')) {
1253
            $format = substr($name, 4);
1254
1255
            return $this->importFrom($format, reset($params));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->importFrom...ormat, reset($params)); (Selfprice\Models\Selfprice\Base\Selfprice) is incompatible with the return type documented by Selfprice\Models\Selfprice\Base\Selfprice::__call of type array|string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
1256
        }
1257
1258
        if (0 === strpos($name, 'to')) {
1259
            $format = substr($name, 2);
1260
            $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
1261
1262
            return $this->exportTo($format, $includeLazyLoadColumns);
1263
        }
1264
1265
        throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
1266
    }
1267
1268
}
1269