Task::postSave()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Core\Models\Task\Base;
4
5
use \DateTime;
6
use \Exception;
7
use \PDO;
8
use Core\Models\Task\TaskQuery as ChildTaskQuery;
9
use Core\Models\Task\Map\TaskTableMap;
10
use Propel\Runtime\Propel;
11
use Propel\Runtime\ActiveQuery\Criteria;
12
use Propel\Runtime\ActiveQuery\ModelCriteria;
13
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
14
use Propel\Runtime\Collection\Collection;
15
use Propel\Runtime\Connection\ConnectionInterface;
16
use Propel\Runtime\Exception\BadMethodCallException;
17
use Propel\Runtime\Exception\LogicException;
18
use Propel\Runtime\Exception\PropelException;
19
use Propel\Runtime\Map\TableMap;
20
use Propel\Runtime\Parser\AbstractParser;
21
use Propel\Runtime\Util\PropelDateTime;
22
23
/**
24
 * Base class that represents a row from the 'tasks' table.
25
 *
26
 *
27
 *
28
* @package    propel.generator.Models.Task.Base
29
*/
30
abstract class Task implements ActiveRecordInterface
31
{
32
    /**
33
     * TableMap class name
34
     */
35
    const TABLE_MAP = '\\Core\\Models\\Task\\Map\\TaskTableMap';
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 created_at field.
72
     * @var        \DateTime
73
     */
74
    protected $created_at;
75
76
    /**
77
     * The value for the updated_at field.
78
     * @var        \DateTime
79
     */
80
    protected $updated_at;
81
82
    /**
83
     * Flag to prevent endless save loop, if this object is referenced
84
     * by another object which falls in this transaction.
85
     *
86
     * @var boolean
87
     */
88
    protected $alreadyInSave = false;
89
90
    /**
91
     * Initializes internal state of Core\Models\Task\Base\Task object.
92
     */
93
    public function __construct()
94
    {
95
    }
96
97
    /**
98
     * Returns whether the object has been modified.
99
     *
100
     * @return boolean True if the object has been modified.
101
     */
102
    public function isModified()
103
    {
104
        return !!$this->modifiedColumns;
105
    }
106
107
    /**
108
     * Has specified column been modified?
109
     *
110
     * @param  string  $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID
111
     * @return boolean True if $col has been modified.
112
     */
113
    public function isColumnModified($col)
114
    {
115
        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...
116
    }
117
118
    /**
119
     * Get the columns that have been modified in this object.
120
     * @return array A unique list of the modified column names for this object.
121
     */
122
    public function getModifiedColumns()
123
    {
124
        return $this->modifiedColumns ? array_keys($this->modifiedColumns) : [];
125
    }
126
127
    /**
128
     * Returns whether the object has ever been saved.  This will
129
     * be false, if the object was retrieved from storage or was created
130
     * and then saved.
131
     *
132
     * @return boolean true, if the object has never been persisted.
133
     */
134
    public function isNew()
135
    {
136
        return $this->new;
137
    }
138
139
    /**
140
     * Setter for the isNew attribute.  This method will be called
141
     * by Propel-generated children and objects.
142
     *
143
     * @param boolean $b the state of the object.
144
     */
145
    public function setNew($b)
146
    {
147
        $this->new = (boolean) $b;
148
    }
149
150
    /**
151
     * Whether this object has been deleted.
152
     * @return boolean The deleted state of this object.
153
     */
154
    public function isDeleted()
155
    {
156
        return $this->deleted;
157
    }
158
159
    /**
160
     * Specify whether this object has been deleted.
161
     * @param  boolean $b The deleted state of this object.
162
     * @return void
163
     */
164
    public function setDeleted($b)
165
    {
166
        $this->deleted = (boolean) $b;
167
    }
168
169
    /**
170
     * Sets the modified state for the object to be false.
171
     * @param  string $col If supplied, only the specified column is reset.
172
     * @return void
173
     */
174 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...
175
    {
176
        if (null !== $col) {
177
            if (isset($this->modifiedColumns[$col])) {
178
                unset($this->modifiedColumns[$col]);
179
            }
180
        } else {
181
            $this->modifiedColumns = array();
182
        }
183
    }
184
185
    /**
186
     * Compares this with another <code>Task</code> instance.  If
187
     * <code>obj</code> is an instance of <code>Task</code>, delegates to
188
     * <code>equals(Task)</code>.  Otherwise, returns <code>false</code>.
189
     *
190
     * @param  mixed   $obj The object to compare to.
191
     * @return boolean Whether equal to the object specified.
192
     */
193 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...
194
    {
195
        if (!$obj instanceof static) {
196
            return false;
197
        }
198
199
        if ($this === $obj) {
200
            return true;
201
        }
202
203
        if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) {
204
            return false;
205
        }
206
207
        return $this->getPrimaryKey() === $obj->getPrimaryKey();
208
    }
209
210
    /**
211
     * Get the associative array of the virtual columns in this object
212
     *
213
     * @return array
214
     */
215
    public function getVirtualColumns()
216
    {
217
        return $this->virtualColumns;
218
    }
219
220
    /**
221
     * Checks the existence of a virtual column in this object
222
     *
223
     * @param  string  $name The virtual column name
224
     * @return boolean
225
     */
226
    public function hasVirtualColumn($name)
227
    {
228
        return array_key_exists($name, $this->virtualColumns);
229
    }
230
231
    /**
232
     * Get the value of a virtual column in this object
233
     *
234
     * @param  string $name The virtual column name
235
     * @return mixed
236
     *
237
     * @throws PropelException
238
     */
239 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...
240
    {
241
        if (!$this->hasVirtualColumn($name)) {
242
            throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name));
243
        }
244
245
        return $this->virtualColumns[$name];
246
    }
247
248
    /**
249
     * Set the value of a virtual column in this object
250
     *
251
     * @param string $name  The virtual column name
252
     * @param mixed  $value The value to give to the virtual column
253
     *
254
     * @return $this|Task The current object, for fluid interface
255
     */
256
    public function setVirtualColumn($name, $value)
257
    {
258
        $this->virtualColumns[$name] = $value;
259
260
        return $this;
261
    }
262
263
    /**
264
     * Logs a message using Propel::log().
265
     *
266
     * @param  string  $msg
267
     * @param  int     $priority One of the Propel::LOG_* logging levels
268
     * @return boolean
269
     */
270
    protected function log($msg, $priority = Propel::LOG_INFO)
271
    {
272
        return Propel::log(get_class($this) . ': ' . $msg, $priority);
273
    }
274
275
    /**
276
     * Export the current object properties to a string, using a given parser format
277
     * <code>
278
     * $book = BookQuery::create()->findPk(9012);
279
     * echo $book->exportTo('JSON');
280
     *  => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
281
     * </code>
282
     *
283
     * @param  mixed   $parser                 A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
284
     * @param  boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
285
     * @return string  The exported data
286
     */
287 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...
288
    {
289
        if (!$parser instanceof AbstractParser) {
290
            $parser = AbstractParser::getParser($parser);
291
        }
292
293
        return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true));
0 ignored issues
show
Unused Code introduced by
The call to Task::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 Core\Models\Task\Base\Task::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...
294
    }
295
296
    /**
297
     * Clean up internal collections prior to serializing
298
     * Avoids recursive loops that turn into segmentation faults when serializing
299
     */
300
    public function __sleep()
301
    {
302
        $this->clearAllReferences();
0 ignored issues
show
Unused Code introduced by
The call to the method Core\Models\Task\Base\Task::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...
303
304
        return array_keys(get_object_vars($this));
305
    }
306
307
    /**
308
     * Get the [id] column value.
309
     *
310
     * @return int
311
     */
312
    public function getId()
313
    {
314
        return $this->id;
315
    }
316
317
    /**
318
     * Get the [optionally formatted] temporal [created_at] column value.
319
     *
320
     *
321
     * @param      string $format The date/time format string (either date()-style or strftime()-style).
322
     *                            If format is NULL, then the raw DateTime object will be returned.
323
     *
324
     * @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
325
     *
326
     * @throws PropelException - if unable to parse/validate the date/time value.
327
     */
328 View Code Duplication
    public function getCreatedAt($format = 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...
329
    {
330
        if ($format === null) {
331
            return $this->created_at;
332
        } else {
333
            return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null;
334
        }
335
    }
336
337
    /**
338
     * Get the [optionally formatted] temporal [updated_at] column value.
339
     *
340
     *
341
     * @param      string $format The date/time format string (either date()-style or strftime()-style).
342
     *                            If format is NULL, then the raw DateTime object will be returned.
343
     *
344
     * @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
345
     *
346
     * @throws PropelException - if unable to parse/validate the date/time value.
347
     */
348 View Code Duplication
    public function getUpdatedAt($format = 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...
349
    {
350
        if ($format === null) {
351
            return $this->updated_at;
352
        } else {
353
            return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null;
354
        }
355
    }
356
357
    /**
358
     * Set the value of [id] column.
359
     *
360
     * @param int $v new value
361
     * @return $this|\Core\Models\Task\Task The current object (for fluent API support)
362
     */
363
    public function setId($v)
364
    {
365
        if ($v !== null) {
366
            $v = (int) $v;
367
        }
368
369
        if ($this->id !== $v) {
370
            $this->id = $v;
371
            $this->modifiedColumns[TaskTableMap::COL_ID] = true;
372
        }
373
374
        return $this;
375
    } // setId()
376
377
    /**
378
     * Sets the value of [created_at] column to a normalized version of the date/time value specified.
379
     *
380
     * @param  mixed $v string, integer (timestamp), or \DateTime value.
381
     *               Empty strings are treated as NULL.
382
     * @return $this|\Core\Models\Task\Task The current object (for fluent API support)
383
     */
384 View Code Duplication
    public function setCreatedAt($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...
385
    {
386
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
387
        if ($this->created_at !== null || $dt !== null) {
388
            if ($this->created_at === null || $dt === null || $dt->format("Y-m-d H:i:s") !== $this->created_at->format("Y-m-d H:i:s")) {
389
                $this->created_at = $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 $created_at 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...
390
                $this->modifiedColumns[TaskTableMap::COL_CREATED_AT] = true;
391
            }
392
        } // if either are not null
393
394
        return $this;
395
    } // setCreatedAt()
396
397
    /**
398
     * Sets the value of [updated_at] column to a normalized version of the date/time value specified.
399
     *
400
     * @param  mixed $v string, integer (timestamp), or \DateTime value.
401
     *               Empty strings are treated as NULL.
402
     * @return $this|\Core\Models\Task\Task The current object (for fluent API support)
403
     */
404 View Code Duplication
    public function setUpdatedAt($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...
405
    {
406
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
407
        if ($this->updated_at !== null || $dt !== null) {
408
            if ($this->updated_at === null || $dt === null || $dt->format("Y-m-d H:i:s") !== $this->updated_at->format("Y-m-d H:i:s")) {
409
                $this->updated_at = $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 $updated_at 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...
410
                $this->modifiedColumns[TaskTableMap::COL_UPDATED_AT] = true;
411
            }
412
        } // if either are not null
413
414
        return $this;
415
    } // setUpdatedAt()
416
417
    /**
418
     * Indicates whether the columns in this object are only set to default values.
419
     *
420
     * This method can be used in conjunction with isModified() to indicate whether an object is both
421
     * modified _and_ has some values set which are non-default.
422
     *
423
     * @return boolean Whether the columns in this object are only been set with default values.
424
     */
425
    public function hasOnlyDefaultValues()
426
    {
427
        // otherwise, everything was equal, so return TRUE
428
        return true;
429
    } // hasOnlyDefaultValues()
430
431
    /**
432
     * Hydrates (populates) the object variables with values from the database resultset.
433
     *
434
     * An offset (0-based "start column") is specified so that objects can be hydrated
435
     * with a subset of the columns in the resultset rows.  This is needed, for example,
436
     * for results of JOIN queries where the resultset row includes columns from two or
437
     * more tables.
438
     *
439
     * @param array   $row       The row returned by DataFetcher->fetch().
440
     * @param int     $startcol  0-based offset column which indicates which restultset column to start with.
441
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
442
     * @param string  $indexType The index type of $row. Mostly DataFetcher->getIndexType().
443
                                  One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
444
     *                            TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
445
     *
446
     * @return int             next starting column
447
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
448
     */
449
    public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM)
450
    {
451
        try {
452
453
            $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : TaskTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
454
            $this->id = (null !== $col) ? (int) $col : null;
455
456
            $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : TaskTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
457
            if ($col === '0000-00-00 00:00:00') {
458
                $col = null;
459
            }
460
            $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, 'DateTime') : null;
461
462
            $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : TaskTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
463
            if ($col === '0000-00-00 00:00:00') {
464
                $col = null;
465
            }
466
            $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, 'DateTime') : null;
467
            $this->resetModified();
468
469
            $this->setNew(false);
470
471
            if ($rehydrate) {
472
                $this->ensureConsistency();
473
            }
474
475
            return $startcol + 3; // 3 = TaskTableMap::NUM_HYDRATE_COLUMNS.
476
477
        } catch (Exception $e) {
478
            throw new PropelException(sprintf('Error populating %s object', '\\Core\\Models\\Task\\Task'), 0, $e);
479
        }
480
    }
481
482
    /**
483
     * Checks and repairs the internal consistency of the object.
484
     *
485
     * This method is executed after an already-instantiated object is re-hydrated
486
     * from the database.  It exists to check any foreign keys to make sure that
487
     * the objects related to the current object are correct based on foreign key.
488
     *
489
     * You can override this method in the stub class, but you should always invoke
490
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
491
     * in case your model changes.
492
     *
493
     * @throws PropelException
494
     */
495
    public function ensureConsistency()
496
    {
497
    } // ensureConsistency
498
499
    /**
500
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
501
     *
502
     * This will only work if the object has been saved and has a valid primary key set.
503
     *
504
     * @param      boolean $deep (optional) Whether to also de-associated any related objects.
505
     * @param      ConnectionInterface $con (optional) The ConnectionInterface connection to use.
506
     * @return void
507
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
508
     */
509 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...
510
    {
511
        if ($this->isDeleted()) {
512
            throw new PropelException("Cannot reload a deleted object.");
513
        }
514
515
        if ($this->isNew()) {
516
            throw new PropelException("Cannot reload an unsaved object.");
517
        }
518
519
        if ($con === null) {
520
            $con = Propel::getServiceContainer()->getReadConnection(TaskTableMap::DATABASE_NAME);
521
        }
522
523
        // We don't need to alter the object instance pool; we're just modifying this instance
524
        // already in the pool.
525
526
        $dataFetcher = ChildTaskQuery::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...
527
        $row = $dataFetcher->fetch();
528
        $dataFetcher->close();
529
        if (!$row) {
530
            throw new PropelException('Cannot find matching row in the database to reload object values.');
531
        }
532
        $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate
533
534
        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...
535
536
        } // 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...
537
    }
538
539
    /**
540
     * Removes this object from datastore and sets delete attribute.
541
     *
542
     * @param      ConnectionInterface $con
543
     * @return void
544
     * @throws PropelException
545
     * @see Task::setDeleted()
546
     * @see Task::isDeleted()
547
     */
548 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...
549
    {
550
        if ($this->isDeleted()) {
551
            throw new PropelException("This object has already been deleted.");
552
        }
553
554
        if ($con === null) {
555
            $con = Propel::getServiceContainer()->getWriteConnection(TaskTableMap::DATABASE_NAME);
556
        }
557
558
        $con->transaction(function () use ($con) {
559
            $deleteQuery = ChildTaskQuery::create()
560
                ->filterByPrimaryKey($this->getPrimaryKey());
561
            $ret = $this->preDelete($con);
562
            if ($ret) {
563
                $deleteQuery->delete($con);
564
                $this->postDelete($con);
565
                $this->setDeleted(true);
566
            }
567
        });
568
    }
569
570
    /**
571
     * Persists this object to the database.
572
     *
573
     * If the object is new, it inserts it; otherwise an update is performed.
574
     * All modified related objects will also be persisted in the doSave()
575
     * method.  This method wraps all precipitate database operations in a
576
     * single transaction.
577
     *
578
     * @param      ConnectionInterface $con
579
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
580
     * @throws PropelException
581
     * @see doSave()
582
     */
583 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...
584
    {
585
        if ($this->isDeleted()) {
586
            throw new PropelException("You cannot save an object that has been deleted.");
587
        }
588
589
        if ($con === null) {
590
            $con = Propel::getServiceContainer()->getWriteConnection(TaskTableMap::DATABASE_NAME);
591
        }
592
593
        return $con->transaction(function () use ($con) {
594
            $isInsert = $this->isNew();
595
            $ret = $this->preSave($con);
596
            if ($isInsert) {
597
                $ret = $ret && $this->preInsert($con);
598
            } else {
599
                $ret = $ret && $this->preUpdate($con);
600
            }
601
            if ($ret) {
602
                $affectedRows = $this->doSave($con);
603
                if ($isInsert) {
604
                    $this->postInsert($con);
605
                } else {
606
                    $this->postUpdate($con);
607
                }
608
                $this->postSave($con);
609
                TaskTableMap::addInstanceToPool($this);
610
            } else {
611
                $affectedRows = 0;
612
            }
613
614
            return $affectedRows;
615
        });
616
    }
617
618
    /**
619
     * Performs the work of inserting or updating the row in the database.
620
     *
621
     * If the object is new, it inserts it; otherwise an update is performed.
622
     * All related objects are also updated in this method.
623
     *
624
     * @param      ConnectionInterface $con
625
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
626
     * @throws PropelException
627
     * @see save()
628
     */
629 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...
630
    {
631
        $affectedRows = 0; // initialize var to track total num of affected rows
632
        if (!$this->alreadyInSave) {
633
            $this->alreadyInSave = true;
634
635
            if ($this->isNew() || $this->isModified()) {
636
                // persist changes
637
                if ($this->isNew()) {
638
                    $this->doInsert($con);
639
                    $affectedRows += 1;
640
                } else {
641
                    $affectedRows += $this->doUpdate($con);
642
                }
643
                $this->resetModified();
644
            }
645
646
            $this->alreadyInSave = false;
647
648
        }
649
650
        return $affectedRows;
651
    } // doSave()
652
653
    /**
654
     * Insert the row in the database.
655
     *
656
     * @param      ConnectionInterface $con
657
     *
658
     * @throws PropelException
659
     * @see doSave()
660
     */
661
    protected function doInsert(ConnectionInterface $con)
662
    {
663
        $modifiedColumns = array();
664
        $index = 0;
665
666
        $this->modifiedColumns[TaskTableMap::COL_ID] = true;
667
        if (null !== $this->id) {
668
            throw new PropelException('Cannot insert a value for auto-increment primary key (' . TaskTableMap::COL_ID . ')');
669
        }
670
671
         // check the columns in natural order for more readable SQL queries
672
        if ($this->isColumnModified(TaskTableMap::COL_ID)) {
673
            $modifiedColumns[':p' . $index++]  = 'id';
674
        }
675
        if ($this->isColumnModified(TaskTableMap::COL_CREATED_AT)) {
676
            $modifiedColumns[':p' . $index++]  = 'created_at';
677
        }
678
        if ($this->isColumnModified(TaskTableMap::COL_UPDATED_AT)) {
679
            $modifiedColumns[':p' . $index++]  = 'updated_at';
680
        }
681
682
        $sql = sprintf(
683
            'INSERT INTO tasks (%s) VALUES (%s)',
684
            implode(', ', $modifiedColumns),
685
            implode(', ', array_keys($modifiedColumns))
686
        );
687
688
        try {
689
            $stmt = $con->prepare($sql);
690 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...
691
                switch ($columnName) {
692
                    case 'id':
693
                        $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
694
                        break;
695
                    case 'created_at':
696
                        $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
697
                        break;
698
                    case 'updated_at':
699
                        $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
700
                        break;
701
                }
702
            }
703
            $stmt->execute();
704
        } catch (Exception $e) {
705
            Propel::log($e->getMessage(), Propel::LOG_ERR);
706
            throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
707
        }
708
709
        try {
710
            $pk = $con->lastInsertId();
711
        } catch (Exception $e) {
712
            throw new PropelException('Unable to get autoincrement id.', 0, $e);
713
        }
714
        $this->setId($pk);
715
716
        $this->setNew(false);
717
    }
718
719
    /**
720
     * Update the row in the database.
721
     *
722
     * @param      ConnectionInterface $con
723
     *
724
     * @return Integer Number of updated rows
725
     * @see doSave()
726
     */
727
    protected function doUpdate(ConnectionInterface $con)
728
    {
729
        $selectCriteria = $this->buildPkeyCriteria();
730
        $valuesCriteria = $this->buildCriteria();
731
732
        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...
733
    }
734
735
    /**
736
     * Retrieves a field from the object by name passed in as a string.
737
     *
738
     * @param      string $name name
739
     * @param      string $type The type of fieldname the $name is of:
740
     *                     one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
741
     *                     TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
742
     *                     Defaults to TableMap::TYPE_PHPNAME.
743
     * @return mixed Value of field.
744
     */
745 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...
746
    {
747
        $pos = TaskTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
748
        $field = $this->getByPosition($pos);
749
750
        return $field;
751
    }
752
753
    /**
754
     * Retrieves a field from the object by Position as specified in the xml schema.
755
     * Zero-based.
756
     *
757
     * @param      int $pos position in xml schema
758
     * @return mixed Value of field at $pos
759
     */
760
    public function getByPosition($pos)
761
    {
762
        switch ($pos) {
763
            case 0:
764
                return $this->getId();
765
                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...
766
            case 1:
767
                return $this->getCreatedAt();
768
                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...
769
            case 2:
770
                return $this->getUpdatedAt();
771
                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...
772
            default:
773
                return null;
774
                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...
775
        } // switch()
776
    }
777
778
    /**
779
     * Exports the object as an array.
780
     *
781
     * You can specify the key type of the array by passing one of the class
782
     * type constants.
783
     *
784
     * @param     string  $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
785
     *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
786
     *                    Defaults to TableMap::TYPE_PHPNAME.
787
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
788
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
789
     *
790
     * @return array an associative array containing the field names (as keys) and field values
791
     */
792
    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...
793
    {
794
795
        if (isset($alreadyDumpedObjects['Task'][$this->hashCode()])) {
796
            return '*RECURSION*';
797
        }
798
        $alreadyDumpedObjects['Task'][$this->hashCode()] = true;
799
        $keys = TaskTableMap::getFieldNames($keyType);
800
        $result = array(
801
            $keys[0] => $this->getId(),
802
            $keys[1] => $this->getCreatedAt(),
803
            $keys[2] => $this->getUpdatedAt(),
804
        );
805
806
        $utc = new \DateTimeZone('utc');
807 View Code Duplication
        if ($result[$keys[1]] 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...
808
            // When changing timezone we don't want to change existing instances
809
            $dateTime = clone $result[$keys[1]];
810
            $result[$keys[1]] = $dateTime->setTimezone($utc)->format('Y-m-d\TH:i:s\Z');
811
        }
812
813 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...
814
            // When changing timezone we don't want to change existing instances
815
            $dateTime = clone $result[$keys[2]];
816
            $result[$keys[2]] = $dateTime->setTimezone($utc)->format('Y-m-d\TH:i:s\Z');
817
        }
818
819
        $virtualColumns = $this->virtualColumns;
820
        foreach ($virtualColumns as $key => $virtualColumn) {
821
            $result[$key] = $virtualColumn;
822
        }
823
824
825
        return $result;
826
    }
827
828
    /**
829
     * Sets a field from the object by name passed in as a string.
830
     *
831
     * @param  string $name
832
     * @param  mixed  $value field value
833
     * @param  string $type The type of fieldname the $name is of:
834
     *                one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
835
     *                TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
836
     *                Defaults to TableMap::TYPE_PHPNAME.
837
     * @return $this|\Core\Models\Task\Task
838
     */
839
    public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME)
840
    {
841
        $pos = TaskTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
842
843
        return $this->setByPosition($pos, $value);
844
    }
845
846
    /**
847
     * Sets a field from the object by Position as specified in the xml schema.
848
     * Zero-based.
849
     *
850
     * @param  int $pos position in xml schema
851
     * @param  mixed $value field value
852
     * @return $this|\Core\Models\Task\Task
853
     */
854
    public function setByPosition($pos, $value)
855
    {
856
        switch ($pos) {
857
            case 0:
858
                $this->setId($value);
859
                break;
860
            case 1:
861
                $this->setCreatedAt($value);
862
                break;
863
            case 2:
864
                $this->setUpdatedAt($value);
865
                break;
866
        } // switch()
867
868
        return $this;
869
    }
870
871
    /**
872
     * Populates the object using an array.
873
     *
874
     * This is particularly useful when populating an object from one of the
875
     * request arrays (e.g. $_POST).  This method goes through the column
876
     * names, checking to see whether a matching key exists in populated
877
     * array. If so the setByName() method is called for that column.
878
     *
879
     * You can specify the key type of the array by additionally passing one
880
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
881
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
882
     * The default key type is the column's TableMap::TYPE_PHPNAME.
883
     *
884
     * @param      array  $arr     An array to populate the object from.
885
     * @param      string $keyType The type of keys the array uses.
886
     * @return void
887
     */
888
    public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME)
889
    {
890
        $keys = TaskTableMap::getFieldNames($keyType);
891
892
        if (array_key_exists($keys[0], $arr)) {
893
            $this->setId($arr[$keys[0]]);
894
        }
895
        if (array_key_exists($keys[1], $arr)) {
896
            $this->setCreatedAt($arr[$keys[1]]);
897
        }
898
        if (array_key_exists($keys[2], $arr)) {
899
            $this->setUpdatedAt($arr[$keys[2]]);
900
        }
901
    }
902
903
     /**
904
     * Populate the current object from a string, using a given parser format
905
     * <code>
906
     * $book = new Book();
907
     * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
908
     * </code>
909
     *
910
     * You can specify the key type of the array by additionally passing one
911
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
912
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
913
     * The default key type is the column's TableMap::TYPE_PHPNAME.
914
     *
915
     * @param mixed $parser A AbstractParser instance,
916
     *                       or a format name ('XML', 'YAML', 'JSON', 'CSV')
917
     * @param string $data The source data to import from
918
     * @param string $keyType The type of keys the array uses.
919
     *
920
     * @return $this|\Core\Models\Task\Task The current object, for fluid interface
921
     */
922 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...
923
    {
924
        if (!$parser instanceof AbstractParser) {
925
            $parser = AbstractParser::getParser($parser);
926
        }
927
928
        $this->fromArray($parser->toArray($data), $keyType);
929
930
        return $this;
931
    }
932
933
    /**
934
     * Build a Criteria object containing the values of all modified columns in this object.
935
     *
936
     * @return Criteria The Criteria object containing all modified values.
937
     */
938
    public function buildCriteria()
939
    {
940
        $criteria = new Criteria(TaskTableMap::DATABASE_NAME);
941
942
        if ($this->isColumnModified(TaskTableMap::COL_ID)) {
943
            $criteria->add(TaskTableMap::COL_ID, $this->id);
944
        }
945
        if ($this->isColumnModified(TaskTableMap::COL_CREATED_AT)) {
946
            $criteria->add(TaskTableMap::COL_CREATED_AT, $this->created_at);
947
        }
948
        if ($this->isColumnModified(TaskTableMap::COL_UPDATED_AT)) {
949
            $criteria->add(TaskTableMap::COL_UPDATED_AT, $this->updated_at);
950
        }
951
952
        return $criteria;
953
    }
954
955
    /**
956
     * Builds a Criteria object containing the primary key for this object.
957
     *
958
     * Unlike buildCriteria() this method includes the primary key values regardless
959
     * of whether or not they have been modified.
960
     *
961
     * @throws LogicException if no primary key is defined
962
     *
963
     * @return Criteria The Criteria object containing value(s) for primary key(s).
964
     */
965
    public function buildPkeyCriteria()
966
    {
967
        $criteria = ChildTaskQuery::create();
968
        $criteria->add(TaskTableMap::COL_ID, $this->id);
969
970
        return $criteria;
971
    }
972
973
    /**
974
     * If the primary key is not null, return the hashcode of the
975
     * primary key. Otherwise, return the hash code of the object.
976
     *
977
     * @return int Hashcode
978
     */
979 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...
980
    {
981
        $validPk = null !== $this->getId();
982
983
        $validPrimaryKeyFKs = 0;
984
        $primaryKeyFKs = [];
985
986
        if ($validPk) {
987
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
988
        } elseif ($validPrimaryKeyFKs) {
989
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
990
        }
991
992
        return spl_object_hash($this);
993
    }
994
995
    /**
996
     * Returns the primary key for this object (row).
997
     * @return int
998
     */
999
    public function getPrimaryKey()
1000
    {
1001
        return $this->getId();
1002
    }
1003
1004
    /**
1005
     * Generic method to set the primary key (id column).
1006
     *
1007
     * @param       int $key Primary key.
1008
     * @return void
1009
     */
1010
    public function setPrimaryKey($key)
1011
    {
1012
        $this->setId($key);
1013
    }
1014
1015
    /**
1016
     * Returns true if the primary key for this object is null.
1017
     * @return boolean
1018
     */
1019
    public function isPrimaryKeyNull()
1020
    {
1021
        return null === $this->getId();
1022
    }
1023
1024
    /**
1025
     * Sets contents of passed object to values from current object.
1026
     *
1027
     * If desired, this method can also make copies of all associated (fkey referrers)
1028
     * objects.
1029
     *
1030
     * @param      object $copyObj An object of \Core\Models\Task\Task (or compatible) type.
1031
     * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1032
     * @param      boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1033
     * @throws PropelException
1034
     */
1035
    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...
1036
    {
1037
        $copyObj->setCreatedAt($this->getCreatedAt());
1038
        $copyObj->setUpdatedAt($this->getUpdatedAt());
1039
        if ($makeNew) {
1040
            $copyObj->setNew(true);
1041
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1042
        }
1043
    }
1044
1045
    /**
1046
     * Makes a copy of this object that will be inserted as a new row in table when saved.
1047
     * It creates a new object filling in the simple attributes, but skipping any primary
1048
     * keys that are defined for the table.
1049
     *
1050
     * If desired, this method can also make copies of all associated (fkey referrers)
1051
     * objects.
1052
     *
1053
     * @param  boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1054
     * @return \Core\Models\Task\Task Clone of current object.
1055
     * @throws PropelException
1056
     */
1057 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...
1058
    {
1059
        // we use get_class(), because this might be a subclass
1060
        $clazz = get_class($this);
1061
        $copyObj = new $clazz();
1062
        $this->copyInto($copyObj, $deepCopy);
1063
1064
        return $copyObj;
1065
    }
1066
1067
    /**
1068
     * Clears the current object, sets all attributes to their default values and removes
1069
     * outgoing references as well as back-references (from other objects to this one. Results probably in a database
1070
     * change of those foreign objects when you call `save` there).
1071
     */
1072 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...
1073
    {
1074
        $this->id = null;
1075
        $this->created_at = null;
1076
        $this->updated_at = null;
1077
        $this->alreadyInSave = false;
1078
        $this->clearAllReferences();
0 ignored issues
show
Unused Code introduced by
The call to the method Core\Models\Task\Base\Task::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...
1079
        $this->resetModified();
1080
        $this->setNew(true);
1081
        $this->setDeleted(false);
1082
    }
1083
1084
    /**
1085
     * Resets all references and back-references to other model objects or collections of model objects.
1086
     *
1087
     * This method is used to reset all php object references (not the actual reference in the database).
1088
     * Necessary for object serialisation.
1089
     *
1090
     * @param      boolean $deep Whether to also clear the references on all referrer objects.
1091
     */
1092
    public function clearAllReferences($deep = false)
1093
    {
1094
        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...
1095
        } // 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...
1096
1097
    }
1098
1099
    /**
1100
     * Return the string representation of this object
1101
     *
1102
     * @return string
1103
     */
1104
    public function __toString()
1105
    {
1106
        return (string) $this->exportTo(TaskTableMap::DEFAULT_STRING_FORMAT);
1107
    }
1108
1109
    /**
1110
     * Code to be run before persisting the object
1111
     * @param  ConnectionInterface $con
1112
     * @return boolean
1113
     */
1114
    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...
1115
    {
1116
        return true;
1117
    }
1118
1119
    /**
1120
     * Code to be run after persisting the object
1121
     * @param ConnectionInterface $con
1122
     */
1123
    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...
1124
    {
1125
1126
    }
1127
1128
    /**
1129
     * Code to be run before inserting to database
1130
     * @param  ConnectionInterface $con
1131
     * @return boolean
1132
     */
1133
    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...
1134
    {
1135
        return true;
1136
    }
1137
1138
    /**
1139
     * Code to be run after inserting to database
1140
     * @param ConnectionInterface $con
1141
     */
1142
    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...
1143
    {
1144
1145
    }
1146
1147
    /**
1148
     * Code to be run before updating the object in database
1149
     * @param  ConnectionInterface $con
1150
     * @return boolean
1151
     */
1152
    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...
1153
    {
1154
        return true;
1155
    }
1156
1157
    /**
1158
     * Code to be run after updating the object in database
1159
     * @param ConnectionInterface $con
1160
     */
1161
    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...
1162
    {
1163
1164
    }
1165
1166
    /**
1167
     * Code to be run before deleting the object in database
1168
     * @param  ConnectionInterface $con
1169
     * @return boolean
1170
     */
1171
    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...
1172
    {
1173
        return true;
1174
    }
1175
1176
    /**
1177
     * Code to be run after deleting the object in database
1178
     * @param ConnectionInterface $con
1179
     */
1180
    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...
1181
    {
1182
1183
    }
1184
1185
1186
    /**
1187
     * Derived method to catches calls to undefined methods.
1188
     *
1189
     * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
1190
     * Allows to define default __call() behavior if you overwrite __call()
1191
     *
1192
     * @param string $name
1193
     * @param mixed  $params
1194
     *
1195
     * @return array|string
1196
     */
1197 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...
1198
    {
1199
        if (0 === strpos($name, 'get')) {
1200
            $virtualColumn = substr($name, 3);
1201
            if ($this->hasVirtualColumn($virtualColumn)) {
1202
                return $this->getVirtualColumn($virtualColumn);
1203
            }
1204
1205
            $virtualColumn = lcfirst($virtualColumn);
1206
            if ($this->hasVirtualColumn($virtualColumn)) {
1207
                return $this->getVirtualColumn($virtualColumn);
1208
            }
1209
        }
1210
1211
        if (0 === strpos($name, 'from')) {
1212
            $format = substr($name, 4);
1213
1214
            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)); (Core\Models\Task\Base\Task) is incompatible with the return type documented by Core\Models\Task\Base\Task::__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...
1215
        }
1216
1217
        if (0 === strpos($name, 'to')) {
1218
            $format = substr($name, 2);
1219
            $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
1220
1221
            return $this->exportTo($format, $includeLazyLoadColumns);
1222
        }
1223
1224
        throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
1225
    }
1226
1227
}
1228