Completed
Pull Request — master (#131)
by De Cramer
05:13 queued 02:26
created

Player::setLogin()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 1
1
<?php
2
3
namespace eXpansion\Framework\PlayersBundle\Model\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\Collection\ObjectCollection;
14
use Propel\Runtime\Connection\ConnectionInterface;
15
use Propel\Runtime\Exception\BadMethodCallException;
16
use Propel\Runtime\Exception\LogicException;
17
use Propel\Runtime\Exception\PropelException;
18
use Propel\Runtime\Map\TableMap;
19
use Propel\Runtime\Parser\AbstractParser;
20
use Propel\Runtime\Util\PropelDateTime;
21
use eXpansion\Bundle\LocalRecords\Model\Record;
22
use eXpansion\Bundle\LocalRecords\Model\RecordQuery;
23
use eXpansion\Bundle\LocalRecords\Model\Base\Record as BaseRecord;
24
use eXpansion\Bundle\LocalRecords\Model\Map\RecordTableMap;
25
use eXpansion\Framework\PlayersBundle\Model\Player as ChildPlayer;
26
use eXpansion\Framework\PlayersBundle\Model\PlayerQuery as ChildPlayerQuery;
27
use eXpansion\Framework\PlayersBundle\Model\Map\PlayerTableMap;
28
29
/**
30
 * Base class that represents a row from the 'player' table.
31
 *
32
 *
33
 *
34
 * @package    propel.generator.src.eXpansion.Framework.PlayersBundle.Model.Base
35
 */
36
abstract class Player implements ActiveRecordInterface
37
{
38
    /**
39
     * TableMap class name
40
     */
41
    const TABLE_MAP = '\\eXpansion\\Framework\\PlayersBundle\\Model\\Map\\PlayerTableMap';
42
43
44
    /**
45
     * attribute to determine if this object has previously been saved.
46
     * @var boolean
47
     */
48
    protected $new = true;
49
50
    /**
51
     * attribute to determine whether this object has been deleted.
52
     * @var boolean
53
     */
54
    protected $deleted = false;
55
56
    /**
57
     * The columns that have been modified in current object.
58
     * Tracking modified columns allows us to only update modified columns.
59
     * @var array
60
     */
61
    protected $modifiedColumns = array();
62
63
    /**
64
     * The (virtual) columns that are added at runtime
65
     * The formatters can add supplementary columns based on a resultset
66
     * @var array
67
     */
68
    protected $virtualColumns = array();
69
70
    /**
71
     * The value for the id field.
72
     *
73
     * @var        int
74
     */
75
    protected $id;
76
77
    /**
78
     * The value for the login field.
79
     *
80
     * @var        string
81
     */
82
    protected $login;
83
84
    /**
85
     * The value for the nickname field.
86
     *
87
     * @var        string
88
     */
89
    protected $nickname;
90
91
    /**
92
     * The value for the nickname_stripped field.
93
     *
94
     * @var        string
95
     */
96
    protected $nickname_stripped;
97
98
    /**
99
     * The value for the path field.
100
     *
101
     * @var        string
102
     */
103
    protected $path;
104
105
    /**
106
     * The value for the wins field.
107
     *
108
     * @var        int
109
     */
110
    protected $wins;
111
112
    /**
113
     * The value for the online_time field.
114
     *
115
     * @var        int
116
     */
117
    protected $online_time;
118
119
    /**
120
     * The value for the last_online field.
121
     *
122
     * @var        DateTime
123
     */
124
    protected $last_online;
125
126
    /**
127
     * @var        ObjectCollection|Record[] Collection to store aggregation of Record objects.
128
     */
129
    protected $collRecords;
130
    protected $collRecordsPartial;
131
132
    /**
133
     * Flag to prevent endless save loop, if this object is referenced
134
     * by another object which falls in this transaction.
135
     *
136
     * @var boolean
137
     */
138
    protected $alreadyInSave = false;
139
140
    /**
141
     * An array of objects scheduled for deletion.
142
     * @var ObjectCollection|Record[]
143
     */
144
    protected $recordsScheduledForDeletion = null;
145
146
    /**
147
     * Initializes internal state of eXpansion\Framework\PlayersBundle\Model\Base\Player object.
148
     */
149
    public function __construct()
150
    {
151
    }
152
153
    /**
154
     * Returns whether the object has been modified.
155
     *
156
     * @return boolean True if the object has been modified.
157
     */
158
    public function isModified()
159
    {
160
        return !!$this->modifiedColumns;
161
    }
162
163
    /**
164
     * Has specified column been modified?
165
     *
166
     * @param  string  $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID
167
     * @return boolean True if $col has been modified.
168
     */
169
    public function isColumnModified($col)
170
    {
171
        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...
172
    }
173
174
    /**
175
     * Get the columns that have been modified in this object.
176
     * @return array A unique list of the modified column names for this object.
177
     */
178
    public function getModifiedColumns()
179
    {
180
        return $this->modifiedColumns ? array_keys($this->modifiedColumns) : [];
181
    }
182
183
    /**
184
     * Returns whether the object has ever been saved.  This will
185
     * be false, if the object was retrieved from storage or was created
186
     * and then saved.
187
     *
188
     * @return boolean true, if the object has never been persisted.
189
     */
190
    public function isNew()
191
    {
192
        return $this->new;
193
    }
194
195
    /**
196
     * Setter for the isNew attribute.  This method will be called
197
     * by Propel-generated children and objects.
198
     *
199
     * @param boolean $b the state of the object.
200
     */
201
    public function setNew($b)
202
    {
203
        $this->new = (boolean) $b;
204
    }
205
206
    /**
207
     * Whether this object has been deleted.
208
     * @return boolean The deleted state of this object.
209
     */
210
    public function isDeleted()
211
    {
212
        return $this->deleted;
213
    }
214
215
    /**
216
     * Specify whether this object has been deleted.
217
     * @param  boolean $b The deleted state of this object.
218
     * @return void
219
     */
220
    public function setDeleted($b)
221
    {
222
        $this->deleted = (boolean) $b;
223
    }
224
225
    /**
226
     * Sets the modified state for the object to be false.
227
     * @param  string $col If supplied, only the specified column is reset.
228
     * @return void
229
     */
230 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...
231
    {
232
        if (null !== $col) {
233
            if (isset($this->modifiedColumns[$col])) {
234
                unset($this->modifiedColumns[$col]);
235
            }
236
        } else {
237
            $this->modifiedColumns = array();
238
        }
239
    }
240
241
    /**
242
     * Compares this with another <code>Player</code> instance.  If
243
     * <code>obj</code> is an instance of <code>Player</code>, delegates to
244
     * <code>equals(Player)</code>.  Otherwise, returns <code>false</code>.
245
     *
246
     * @param  mixed   $obj The object to compare to.
247
     * @return boolean Whether equal to the object specified.
248
     */
249 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...
250
    {
251
        if (!$obj instanceof static) {
252
            return false;
253
        }
254
255
        if ($this === $obj) {
256
            return true;
257
        }
258
259
        if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) {
260
            return false;
261
        }
262
263
        return $this->getPrimaryKey() === $obj->getPrimaryKey();
264
    }
265
266
    /**
267
     * Get the associative array of the virtual columns in this object
268
     *
269
     * @return array
270
     */
271
    public function getVirtualColumns()
272
    {
273
        return $this->virtualColumns;
274
    }
275
276
    /**
277
     * Checks the existence of a virtual column in this object
278
     *
279
     * @param  string  $name The virtual column name
280
     * @return boolean
281
     */
282
    public function hasVirtualColumn($name)
283
    {
284
        return array_key_exists($name, $this->virtualColumns);
285
    }
286
287
    /**
288
     * Get the value of a virtual column in this object
289
     *
290
     * @param  string $name The virtual column name
291
     * @return mixed
292
     *
293
     * @throws PropelException
294
     */
295 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...
296
    {
297
        if (!$this->hasVirtualColumn($name)) {
298
            throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name));
299
        }
300
301
        return $this->virtualColumns[$name];
302
    }
303
304
    /**
305
     * Set the value of a virtual column in this object
306
     *
307
     * @param string $name  The virtual column name
308
     * @param mixed  $value The value to give to the virtual column
309
     *
310
     * @return $this|Player The current object, for fluid interface
311
     */
312
    public function setVirtualColumn($name, $value)
313
    {
314
        $this->virtualColumns[$name] = $value;
315
316
        return $this;
317
    }
318
319
    /**
320
     * Logs a message using Propel::log().
321
     *
322
     * @param  string  $msg
323
     * @param  int     $priority One of the Propel::LOG_* logging levels
324
     * @return boolean
325
     */
326
    protected function log($msg, $priority = Propel::LOG_INFO)
327
    {
328
        return Propel::log(get_class($this) . ': ' . $msg, $priority);
329
    }
330
331
    /**
332
     * Export the current object properties to a string, using a given parser format
333
     * <code>
334
     * $book = BookQuery::create()->findPk(9012);
335
     * echo $book->exportTo('JSON');
336
     *  => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
337
     * </code>
338
     *
339
     * @param  mixed   $parser                 A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
340
     * @param  boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
341
     * @return string  The exported data
342
     */
343 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...
344
    {
345
        if (!$parser instanceof AbstractParser) {
346
            $parser = AbstractParser::getParser($parser);
347
        }
348
349
        return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true));
0 ignored issues
show
Bug introduced by
It seems like $this->toArray(\Propel\R...Columns, array(), true) targeting eXpansion\Framework\Play...\Base\Player::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...
350
    }
351
352
    /**
353
     * Clean up internal collections prior to serializing
354
     * Avoids recursive loops that turn into segmentation faults when serializing
355
     */
356 View Code Duplication
    public function __sleep()
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...
357
    {
358
        $this->clearAllReferences();
359
360
        $cls = new \ReflectionClass($this);
361
        $propertyNames = [];
362
        $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC));
363
364
        foreach($serializableProperties as $property) {
365
            $propertyNames[] = $property->getName();
366
        }
367
368
        return $propertyNames;
369
    }
370
371
    /**
372
     * Get the [id] column value.
373
     *
374
     * @return int
375
     */
376
    public function getId()
377
    {
378
        return $this->id;
379
    }
380
381
    /**
382
     * Get the [login] column value.
383
     *
384
     * @return string
385
     */
386
    public function getLogin()
387
    {
388
        return $this->login;
389
    }
390
391
    /**
392
     * Get the [nickname] column value.
393
     *
394
     * @return string
395
     */
396
    public function getNickname()
397
    {
398
        return $this->nickname;
399
    }
400
401
    /**
402
     * Get the [nickname_stripped] column value.
403
     *
404
     * @return string
405
     */
406
    public function getNicknameStripped()
407
    {
408
        return $this->nickname_stripped;
409
    }
410
411
    /**
412
     * Get the [path] column value.
413
     *
414
     * @return string
415
     */
416
    public function getPath()
417
    {
418
        return $this->path;
419
    }
420
421
    /**
422
     * Get the [wins] column value.
423
     *
424
     * @return int
425
     */
426
    public function getWins()
427
    {
428
        return $this->wins;
429
    }
430
431
    /**
432
     * Get the [online_time] column value.
433
     *
434
     * @return int
435
     */
436
    public function getOnlineTime()
437
    {
438
        return $this->online_time;
439
    }
440
441
    /**
442
     * Get the [optionally formatted] temporal [last_online] column value.
443
     *
444
     *
445
     * @param      string $format The date/time format string (either date()-style or strftime()-style).
446
     *                            If format is NULL, then the raw DateTime object will be returned.
447
     *
448
     * @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
449
     *
450
     * @throws PropelException - if unable to parse/validate the date/time value.
451
     */
452
    public function getLastOnline($format = NULL)
453
    {
454
        if ($format === null) {
455
            return $this->last_online;
456
        } else {
457
            return $this->last_online instanceof \DateTimeInterface ? $this->last_online->format($format) : null;
458
        }
459
    }
460
461
    /**
462
     * Set the value of [id] column.
463
     *
464
     * @param int $v new value
465
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player The current object (for fluent API support)
466
     */
467 View Code Duplication
    public function setId($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...
468
    {
469
        if ($v !== null) {
470
            $v = (int) $v;
471
        }
472
473
        if ($this->id !== $v) {
474
            $this->id = $v;
475
            $this->modifiedColumns[PlayerTableMap::COL_ID] = true;
476
        }
477
478
        return $this;
479
    } // setId()
480
481
    /**
482
     * Set the value of [login] column.
483
     *
484
     * @param string $v new value
485
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player The current object (for fluent API support)
486
     */
487 View Code Duplication
    public function setLogin($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...
488
    {
489
        if ($v !== null) {
490
            $v = (string) $v;
491
        }
492
493
        if ($this->login !== $v) {
494
            $this->login = $v;
495
            $this->modifiedColumns[PlayerTableMap::COL_LOGIN] = true;
496
        }
497
498
        return $this;
499
    } // setLogin()
500
501
    /**
502
     * Set the value of [nickname] column.
503
     *
504
     * @param string $v new value
505
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player The current object (for fluent API support)
506
     */
507 View Code Duplication
    public function setNickname($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...
508
    {
509
        if ($v !== null) {
510
            $v = (string) $v;
511
        }
512
513
        if ($this->nickname !== $v) {
514
            $this->nickname = $v;
515
            $this->modifiedColumns[PlayerTableMap::COL_NICKNAME] = true;
516
        }
517
518
        return $this;
519
    } // setNickname()
520
521
    /**
522
     * Set the value of [nickname_stripped] column.
523
     *
524
     * @param string $v new value
525
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player The current object (for fluent API support)
526
     */
527 View Code Duplication
    public function setNicknameStripped($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...
528
    {
529
        if ($v !== null) {
530
            $v = (string) $v;
531
        }
532
533
        if ($this->nickname_stripped !== $v) {
534
            $this->nickname_stripped = $v;
535
            $this->modifiedColumns[PlayerTableMap::COL_NICKNAME_STRIPPED] = true;
536
        }
537
538
        return $this;
539
    } // setNicknameStripped()
540
541
    /**
542
     * Set the value of [path] column.
543
     *
544
     * @param string $v new value
545
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player The current object (for fluent API support)
546
     */
547 View Code Duplication
    public function setPath($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...
548
    {
549
        if ($v !== null) {
550
            $v = (string) $v;
551
        }
552
553
        if ($this->path !== $v) {
554
            $this->path = $v;
555
            $this->modifiedColumns[PlayerTableMap::COL_PATH] = true;
556
        }
557
558
        return $this;
559
    } // setPath()
560
561
    /**
562
     * Set the value of [wins] column.
563
     *
564
     * @param int $v new value
565
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player The current object (for fluent API support)
566
     */
567 View Code Duplication
    public function setWins($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...
568
    {
569
        if ($v !== null) {
570
            $v = (int) $v;
571
        }
572
573
        if ($this->wins !== $v) {
574
            $this->wins = $v;
575
            $this->modifiedColumns[PlayerTableMap::COL_WINS] = true;
576
        }
577
578
        return $this;
579
    } // setWins()
580
581
    /**
582
     * Set the value of [online_time] column.
583
     *
584
     * @param int $v new value
585
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player The current object (for fluent API support)
586
     */
587 View Code Duplication
    public function setOnlineTime($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...
588
    {
589
        if ($v !== null) {
590
            $v = (int) $v;
591
        }
592
593
        if ($this->online_time !== $v) {
594
            $this->online_time = $v;
595
            $this->modifiedColumns[PlayerTableMap::COL_ONLINE_TIME] = true;
596
        }
597
598
        return $this;
599
    } // setOnlineTime()
600
601
    /**
602
     * Sets the value of [last_online] column to a normalized version of the date/time value specified.
603
     *
604
     * @param  mixed $v string, integer (timestamp), or \DateTimeInterface value.
605
     *               Empty strings are treated as NULL.
606
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player The current object (for fluent API support)
607
     */
608 View Code Duplication
    public function setLastOnline($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...
609
    {
610
        $dt = PropelDateTime::newInstance($v, null, 'DateTime');
611
        if ($this->last_online !== null || $dt !== null) {
612
            if ($this->last_online === null || $dt === null || $dt->format("Y-m-d H:i:s.u") !== $this->last_online->format("Y-m-d H:i:s.u")) {
613
                $this->last_online = $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 $last_online 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...
614
                $this->modifiedColumns[PlayerTableMap::COL_LAST_ONLINE] = true;
615
            }
616
        } // if either are not null
617
618
        return $this;
619
    } // setLastOnline()
620
621
    /**
622
     * Indicates whether the columns in this object are only set to default values.
623
     *
624
     * This method can be used in conjunction with isModified() to indicate whether an object is both
625
     * modified _and_ has some values set which are non-default.
626
     *
627
     * @return boolean Whether the columns in this object are only been set with default values.
628
     */
629
    public function hasOnlyDefaultValues()
630
    {
631
        // otherwise, everything was equal, so return TRUE
632
        return true;
633
    } // hasOnlyDefaultValues()
634
635
    /**
636
     * Hydrates (populates) the object variables with values from the database resultset.
637
     *
638
     * An offset (0-based "start column") is specified so that objects can be hydrated
639
     * with a subset of the columns in the resultset rows.  This is needed, for example,
640
     * for results of JOIN queries where the resultset row includes columns from two or
641
     * more tables.
642
     *
643
     * @param array   $row       The row returned by DataFetcher->fetch().
644
     * @param int     $startcol  0-based offset column which indicates which restultset column to start with.
645
     * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
646
     * @param string  $indexType The index type of $row. Mostly DataFetcher->getIndexType().
647
                                  One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
648
     *                            TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
649
     *
650
     * @return int             next starting column
651
     * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
652
     */
653
    public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM)
654
    {
655
        try {
656
657
            $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : PlayerTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
658
            $this->id = (null !== $col) ? (int) $col : null;
659
660
            $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : PlayerTableMap::translateFieldName('Login', TableMap::TYPE_PHPNAME, $indexType)];
661
            $this->login = (null !== $col) ? (string) $col : null;
662
663
            $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : PlayerTableMap::translateFieldName('Nickname', TableMap::TYPE_PHPNAME, $indexType)];
664
            $this->nickname = (null !== $col) ? (string) $col : null;
665
666
            $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : PlayerTableMap::translateFieldName('NicknameStripped', TableMap::TYPE_PHPNAME, $indexType)];
667
            $this->nickname_stripped = (null !== $col) ? (string) $col : null;
668
669
            $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : PlayerTableMap::translateFieldName('Path', TableMap::TYPE_PHPNAME, $indexType)];
670
            $this->path = (null !== $col) ? (string) $col : null;
671
672
            $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : PlayerTableMap::translateFieldName('Wins', TableMap::TYPE_PHPNAME, $indexType)];
673
            $this->wins = (null !== $col) ? (int) $col : null;
674
675
            $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : PlayerTableMap::translateFieldName('OnlineTime', TableMap::TYPE_PHPNAME, $indexType)];
676
            $this->online_time = (null !== $col) ? (int) $col : null;
677
678
            $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : PlayerTableMap::translateFieldName('LastOnline', TableMap::TYPE_PHPNAME, $indexType)];
679
            if ($col === '0000-00-00 00:00:00') {
680
                $col = null;
681
            }
682
            $this->last_online = (null !== $col) ? PropelDateTime::newInstance($col, null, 'DateTime') : null;
683
            $this->resetModified();
684
685
            $this->setNew(false);
686
687
            if ($rehydrate) {
688
                $this->ensureConsistency();
689
            }
690
691
            return $startcol + 8; // 8 = PlayerTableMap::NUM_HYDRATE_COLUMNS.
692
693
        } catch (Exception $e) {
694
            throw new PropelException(sprintf('Error populating %s object', '\\eXpansion\\Framework\\PlayersBundle\\Model\\Player'), 0, $e);
695
        }
696
    }
697
698
    /**
699
     * Checks and repairs the internal consistency of the object.
700
     *
701
     * This method is executed after an already-instantiated object is re-hydrated
702
     * from the database.  It exists to check any foreign keys to make sure that
703
     * the objects related to the current object are correct based on foreign key.
704
     *
705
     * You can override this method in the stub class, but you should always invoke
706
     * the base method from the overridden method (i.e. parent::ensureConsistency()),
707
     * in case your model changes.
708
     *
709
     * @throws PropelException
710
     */
711
    public function ensureConsistency()
712
    {
713
    } // ensureConsistency
714
715
    /**
716
     * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
717
     *
718
     * This will only work if the object has been saved and has a valid primary key set.
719
     *
720
     * @param      boolean $deep (optional) Whether to also de-associated any related objects.
721
     * @param      ConnectionInterface $con (optional) The ConnectionInterface connection to use.
722
     * @return void
723
     * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
724
     */
725 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...
726
    {
727
        if ($this->isDeleted()) {
728
            throw new PropelException("Cannot reload a deleted object.");
729
        }
730
731
        if ($this->isNew()) {
732
            throw new PropelException("Cannot reload an unsaved object.");
733
        }
734
735
        if ($con === null) {
736
            $con = Propel::getServiceContainer()->getReadConnection(PlayerTableMap::DATABASE_NAME);
737
        }
738
739
        // We don't need to alter the object instance pool; we're just modifying this instance
740
        // already in the pool.
741
742
        $dataFetcher = ChildPlayerQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Propel\Runtime\ActiveQuery\BaseModelCriteria as the method find() does only exist in the following sub-classes of Propel\Runtime\ActiveQuery\BaseModelCriteria: Propel\Bundle\PropelBund...es\Model\Base\BookQuery, Propel\Bundle\PropelBund...ixtures\Model\BookQuery, Propel\Runtime\ActiveQuery\ModelCriteria, eXpansion\Bundle\LocalRe...\Model\Base\RecordQuery, eXpansion\Bundle\LocalRecords\Model\RecordQuery, eXpansion\Framework\Play...\Model\Base\PlayerQuery, eXpansion\Framework\Play...undle\Model\PlayerQuery. 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...
743
        $row = $dataFetcher->fetch();
744
        $dataFetcher->close();
745
        if (!$row) {
746
            throw new PropelException('Cannot find matching row in the database to reload object values.');
747
        }
748
        $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate
749
750
        if ($deep) {  // also de-associate any related objects?
751
752
            $this->collRecords = null;
753
754
        } // 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...
755
    }
756
757
    /**
758
     * Removes this object from datastore and sets delete attribute.
759
     *
760
     * @param      ConnectionInterface $con
761
     * @return void
762
     * @throws PropelException
763
     * @see Player::setDeleted()
764
     * @see Player::isDeleted()
765
     */
766 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...
767
    {
768
        if ($this->isDeleted()) {
769
            throw new PropelException("This object has already been deleted.");
770
        }
771
772
        if ($con === null) {
773
            $con = Propel::getServiceContainer()->getWriteConnection(PlayerTableMap::DATABASE_NAME);
774
        }
775
776
        $con->transaction(function () use ($con) {
777
            $deleteQuery = ChildPlayerQuery::create()
778
                ->filterByPrimaryKey($this->getPrimaryKey());
779
            $ret = $this->preDelete($con);
780
            if ($ret) {
781
                $deleteQuery->delete($con);
782
                $this->postDelete($con);
783
                $this->setDeleted(true);
784
            }
785
        });
786
    }
787
788
    /**
789
     * Persists this object to the database.
790
     *
791
     * If the object is new, it inserts it; otherwise an update is performed.
792
     * All modified related objects will also be persisted in the doSave()
793
     * method.  This method wraps all precipitate database operations in a
794
     * single transaction.
795
     *
796
     * @param      ConnectionInterface $con
797
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
798
     * @throws PropelException
799
     * @see doSave()
800
     */
801
    public function save(ConnectionInterface $con = null)
802
    {
803
        if ($this->isDeleted()) {
804
            throw new PropelException("You cannot save an object that has been deleted.");
805
        }
806
807
        if ($con === null) {
808
            $con = Propel::getServiceContainer()->getWriteConnection(PlayerTableMap::DATABASE_NAME);
809
        }
810
811
        return $con->transaction(function () use ($con) {
812
            $ret = $this->preSave($con);
813
            $isInsert = $this->isNew();
814
            if ($isInsert) {
815
                $ret = $ret && $this->preInsert($con);
816
            } else {
817
                $ret = $ret && $this->preUpdate($con);
818
            }
819 View Code Duplication
            if ($ret) {
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...
820
                $affectedRows = $this->doSave($con);
821
                if ($isInsert) {
822
                    $this->postInsert($con);
823
                } else {
824
                    $this->postUpdate($con);
825
                }
826
                $this->postSave($con);
827
                PlayerTableMap::addInstanceToPool($this);
828
            } else {
829
                $affectedRows = 0;
830
            }
831
832
            return $affectedRows;
833
        });
834
    }
835
836
    /**
837
     * Performs the work of inserting or updating the row in the database.
838
     *
839
     * If the object is new, it inserts it; otherwise an update is performed.
840
     * All related objects are also updated in this method.
841
     *
842
     * @param      ConnectionInterface $con
843
     * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
844
     * @throws PropelException
845
     * @see save()
846
     */
847
    protected function doSave(ConnectionInterface $con)
848
    {
849
        $affectedRows = 0; // initialize var to track total num of affected rows
850
        if (!$this->alreadyInSave) {
851
            $this->alreadyInSave = true;
852
853 View Code Duplication
            if ($this->isNew() || $this->isModified()) {
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...
854
                // persist changes
855
                if ($this->isNew()) {
856
                    $this->doInsert($con);
857
                    $affectedRows += 1;
858
                } else {
859
                    $affectedRows += $this->doUpdate($con);
860
                }
861
                $this->resetModified();
862
            }
863
864
            if ($this->recordsScheduledForDeletion !== null) {
865
                if (!$this->recordsScheduledForDeletion->isEmpty()) {
866
                    foreach ($this->recordsScheduledForDeletion as $record) {
867
                        // need to save related object because we set the relation to null
868
                        $record->save($con);
869
                    }
870
                    $this->recordsScheduledForDeletion = null;
871
                }
872
            }
873
874
            if ($this->collRecords !== null) {
875
                foreach ($this->collRecords as $referrerFK) {
876
                    if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
877
                        $affectedRows += $referrerFK->save($con);
878
                    }
879
                }
880
            }
881
882
            $this->alreadyInSave = false;
883
884
        }
885
886
        return $affectedRows;
887
    } // doSave()
888
889
    /**
890
     * Insert the row in the database.
891
     *
892
     * @param      ConnectionInterface $con
893
     *
894
     * @throws PropelException
895
     * @see doSave()
896
     */
897
    protected function doInsert(ConnectionInterface $con)
898
    {
899
        $modifiedColumns = array();
900
        $index = 0;
901
902
        $this->modifiedColumns[PlayerTableMap::COL_ID] = true;
903
        if (null !== $this->id) {
904
            throw new PropelException('Cannot insert a value for auto-increment primary key (' . PlayerTableMap::COL_ID . ')');
905
        }
906
907
         // check the columns in natural order for more readable SQL queries
908
        if ($this->isColumnModified(PlayerTableMap::COL_ID)) {
909
            $modifiedColumns[':p' . $index++]  = 'id';
910
        }
911
        if ($this->isColumnModified(PlayerTableMap::COL_LOGIN)) {
912
            $modifiedColumns[':p' . $index++]  = 'login';
913
        }
914
        if ($this->isColumnModified(PlayerTableMap::COL_NICKNAME)) {
915
            $modifiedColumns[':p' . $index++]  = 'nickname';
916
        }
917
        if ($this->isColumnModified(PlayerTableMap::COL_NICKNAME_STRIPPED)) {
918
            $modifiedColumns[':p' . $index++]  = 'nickname_stripped';
919
        }
920
        if ($this->isColumnModified(PlayerTableMap::COL_PATH)) {
921
            $modifiedColumns[':p' . $index++]  = 'path';
922
        }
923
        if ($this->isColumnModified(PlayerTableMap::COL_WINS)) {
924
            $modifiedColumns[':p' . $index++]  = 'wins';
925
        }
926
        if ($this->isColumnModified(PlayerTableMap::COL_ONLINE_TIME)) {
927
            $modifiedColumns[':p' . $index++]  = 'online_time';
928
        }
929
        if ($this->isColumnModified(PlayerTableMap::COL_LAST_ONLINE)) {
930
            $modifiedColumns[':p' . $index++]  = 'last_online';
931
        }
932
933
        $sql = sprintf(
934
            'INSERT INTO player (%s) VALUES (%s)',
935
            implode(', ', $modifiedColumns),
936
            implode(', ', array_keys($modifiedColumns))
937
        );
938
939
        try {
940
            $stmt = $con->prepare($sql);
941
            foreach ($modifiedColumns as $identifier => $columnName) {
942
                switch ($columnName) {
943
                    case 'id':
944
                        $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
945
                        break;
946
                    case 'login':
947
                        $stmt->bindValue($identifier, $this->login, PDO::PARAM_STR);
948
                        break;
949
                    case 'nickname':
950
                        $stmt->bindValue($identifier, $this->nickname, PDO::PARAM_STR);
951
                        break;
952
                    case 'nickname_stripped':
953
                        $stmt->bindValue($identifier, $this->nickname_stripped, PDO::PARAM_STR);
954
                        break;
955
                    case 'path':
956
                        $stmt->bindValue($identifier, $this->path, PDO::PARAM_STR);
957
                        break;
958
                    case 'wins':
959
                        $stmt->bindValue($identifier, $this->wins, PDO::PARAM_INT);
960
                        break;
961
                    case 'online_time':
962
                        $stmt->bindValue($identifier, $this->online_time, PDO::PARAM_INT);
963
                        break;
964
                    case 'last_online':
965
                        $stmt->bindValue($identifier, $this->last_online ? $this->last_online->format("Y-m-d H:i:s.u") : null, PDO::PARAM_STR);
966
                        break;
967
                }
968
            }
969
            $stmt->execute();
970
        } catch (Exception $e) {
971
            Propel::log($e->getMessage(), Propel::LOG_ERR);
972
            throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
973
        }
974
975
        try {
976
            $pk = $con->lastInsertId();
977
        } catch (Exception $e) {
978
            throw new PropelException('Unable to get autoincrement id.', 0, $e);
979
        }
980
        $this->setId($pk);
981
982
        $this->setNew(false);
983
    }
984
985
    /**
986
     * Update the row in the database.
987
     *
988
     * @param      ConnectionInterface $con
989
     *
990
     * @return Integer Number of updated rows
991
     * @see doSave()
992
     */
993
    protected function doUpdate(ConnectionInterface $con)
994
    {
995
        $selectCriteria = $this->buildPkeyCriteria();
996
        $valuesCriteria = $this->buildCriteria();
997
998
        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...
999
    }
1000
1001
    /**
1002
     * Retrieves a field from the object by name passed in as a string.
1003
     *
1004
     * @param      string $name name
1005
     * @param      string $type The type of fieldname the $name is of:
1006
     *                     one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
1007
     *                     TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1008
     *                     Defaults to TableMap::TYPE_PHPNAME.
1009
     * @return mixed Value of field.
1010
     */
1011 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...
1012
    {
1013
        $pos = PlayerTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
1014
        $field = $this->getByPosition($pos);
1015
1016
        return $field;
1017
    }
1018
1019
    /**
1020
     * Retrieves a field from the object by Position as specified in the xml schema.
1021
     * Zero-based.
1022
     *
1023
     * @param      int $pos position in xml schema
1024
     * @return mixed Value of field at $pos
1025
     */
1026
    public function getByPosition($pos)
1027
    {
1028
        switch ($pos) {
1029
            case 0:
1030
                return $this->getId();
1031
                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...
1032
            case 1:
1033
                return $this->getLogin();
1034
                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...
1035
            case 2:
1036
                return $this->getNickname();
1037
                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...
1038
            case 3:
1039
                return $this->getNicknameStripped();
1040
                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...
1041
            case 4:
1042
                return $this->getPath();
1043
                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...
1044
            case 5:
1045
                return $this->getWins();
1046
                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...
1047
            case 6:
1048
                return $this->getOnlineTime();
1049
                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...
1050
            case 7:
1051
                return $this->getLastOnline();
1052
                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...
1053
            default:
1054
                return null;
1055
                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...
1056
        } // switch()
1057
    }
1058
1059
    /**
1060
     * Exports the object as an array.
1061
     *
1062
     * You can specify the key type of the array by passing one of the class
1063
     * type constants.
1064
     *
1065
     * @param     string  $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1066
     *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1067
     *                    Defaults to TableMap::TYPE_PHPNAME.
1068
     * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
1069
     * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
1070
     * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
1071
     *
1072
     * @return array an associative array containing the field names (as keys) and field values
1073
     */
1074
    public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
1075
    {
1076
1077
        if (isset($alreadyDumpedObjects['Player'][$this->hashCode()])) {
1078
            return '*RECURSION*';
1079
        }
1080
        $alreadyDumpedObjects['Player'][$this->hashCode()] = true;
1081
        $keys = PlayerTableMap::getFieldNames($keyType);
1082
        $result = array(
1083
            $keys[0] => $this->getId(),
1084
            $keys[1] => $this->getLogin(),
1085
            $keys[2] => $this->getNickname(),
1086
            $keys[3] => $this->getNicknameStripped(),
1087
            $keys[4] => $this->getPath(),
1088
            $keys[5] => $this->getWins(),
1089
            $keys[6] => $this->getOnlineTime(),
1090
            $keys[7] => $this->getLastOnline(),
1091
        );
1092 View Code Duplication
        if ($result[$keys[7]] 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...
1093
            $result[$keys[7]] = $result[$keys[7]]->format('c');
1094
        }
1095
1096
        $virtualColumns = $this->virtualColumns;
1097
        foreach ($virtualColumns as $key => $virtualColumn) {
1098
            $result[$key] = $virtualColumn;
1099
        }
1100
1101 View Code Duplication
        if ($includeForeignObjects) {
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...
1102
            if (null !== $this->collRecords) {
1103
1104
                switch ($keyType) {
1105
                    case TableMap::TYPE_CAMELNAME:
1106
                        $key = 'records';
1107
                        break;
1108
                    case TableMap::TYPE_FIELDNAME:
1109
                        $key = 'records';
1110
                        break;
1111
                    default:
1112
                        $key = 'Records';
1113
                }
1114
1115
                $result[$key] = $this->collRecords->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
1116
            }
1117
        }
1118
1119
        return $result;
1120
    }
1121
1122
    /**
1123
     * Sets a field from the object by name passed in as a string.
1124
     *
1125
     * @param  string $name
1126
     * @param  mixed  $value field value
1127
     * @param  string $type The type of fieldname the $name is of:
1128
     *                one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME
1129
     *                TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1130
     *                Defaults to TableMap::TYPE_PHPNAME.
1131
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player
1132
     */
1133
    public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME)
1134
    {
1135
        $pos = PlayerTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM);
1136
1137
        return $this->setByPosition($pos, $value);
1138
    }
1139
1140
    /**
1141
     * Sets a field from the object by Position as specified in the xml schema.
1142
     * Zero-based.
1143
     *
1144
     * @param  int $pos position in xml schema
1145
     * @param  mixed $value field value
1146
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player
1147
     */
1148
    public function setByPosition($pos, $value)
1149
    {
1150
        switch ($pos) {
1151
            case 0:
1152
                $this->setId($value);
1153
                break;
1154
            case 1:
1155
                $this->setLogin($value);
1156
                break;
1157
            case 2:
1158
                $this->setNickname($value);
1159
                break;
1160
            case 3:
1161
                $this->setNicknameStripped($value);
1162
                break;
1163
            case 4:
1164
                $this->setPath($value);
1165
                break;
1166
            case 5:
1167
                $this->setWins($value);
1168
                break;
1169
            case 6:
1170
                $this->setOnlineTime($value);
1171
                break;
1172
            case 7:
1173
                $this->setLastOnline($value);
1174
                break;
1175
        } // switch()
1176
1177
        return $this;
1178
    }
1179
1180
    /**
1181
     * Populates the object using an array.
1182
     *
1183
     * This is particularly useful when populating an object from one of the
1184
     * request arrays (e.g. $_POST).  This method goes through the column
1185
     * names, checking to see whether a matching key exists in populated
1186
     * array. If so the setByName() method is called for that column.
1187
     *
1188
     * You can specify the key type of the array by additionally passing one
1189
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1190
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1191
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1192
     *
1193
     * @param      array  $arr     An array to populate the object from.
1194
     * @param      string $keyType The type of keys the array uses.
1195
     * @return void
1196
     */
1197
    public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME)
1198
    {
1199
        $keys = PlayerTableMap::getFieldNames($keyType);
1200
1201
        if (array_key_exists($keys[0], $arr)) {
1202
            $this->setId($arr[$keys[0]]);
1203
        }
1204
        if (array_key_exists($keys[1], $arr)) {
1205
            $this->setLogin($arr[$keys[1]]);
1206
        }
1207
        if (array_key_exists($keys[2], $arr)) {
1208
            $this->setNickname($arr[$keys[2]]);
1209
        }
1210
        if (array_key_exists($keys[3], $arr)) {
1211
            $this->setNicknameStripped($arr[$keys[3]]);
1212
        }
1213
        if (array_key_exists($keys[4], $arr)) {
1214
            $this->setPath($arr[$keys[4]]);
1215
        }
1216
        if (array_key_exists($keys[5], $arr)) {
1217
            $this->setWins($arr[$keys[5]]);
1218
        }
1219
        if (array_key_exists($keys[6], $arr)) {
1220
            $this->setOnlineTime($arr[$keys[6]]);
1221
        }
1222
        if (array_key_exists($keys[7], $arr)) {
1223
            $this->setLastOnline($arr[$keys[7]]);
1224
        }
1225
    }
1226
1227
     /**
1228
     * Populate the current object from a string, using a given parser format
1229
     * <code>
1230
     * $book = new Book();
1231
     * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}');
1232
     * </code>
1233
     *
1234
     * You can specify the key type of the array by additionally passing one
1235
     * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME,
1236
     * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
1237
     * The default key type is the column's TableMap::TYPE_PHPNAME.
1238
     *
1239
     * @param mixed $parser A AbstractParser instance,
1240
     *                       or a format name ('XML', 'YAML', 'JSON', 'CSV')
1241
     * @param string $data The source data to import from
1242
     * @param string $keyType The type of keys the array uses.
1243
     *
1244
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player The current object, for fluid interface
1245
     */
1246 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...
1247
    {
1248
        if (!$parser instanceof AbstractParser) {
1249
            $parser = AbstractParser::getParser($parser);
1250
        }
1251
1252
        $this->fromArray($parser->toArray($data), $keyType);
1253
1254
        return $this;
1255
    }
1256
1257
    /**
1258
     * Build a Criteria object containing the values of all modified columns in this object.
1259
     *
1260
     * @return Criteria The Criteria object containing all modified values.
1261
     */
1262
    public function buildCriteria()
1263
    {
1264
        $criteria = new Criteria(PlayerTableMap::DATABASE_NAME);
1265
1266
        if ($this->isColumnModified(PlayerTableMap::COL_ID)) {
1267
            $criteria->add(PlayerTableMap::COL_ID, $this->id);
1268
        }
1269
        if ($this->isColumnModified(PlayerTableMap::COL_LOGIN)) {
1270
            $criteria->add(PlayerTableMap::COL_LOGIN, $this->login);
1271
        }
1272
        if ($this->isColumnModified(PlayerTableMap::COL_NICKNAME)) {
1273
            $criteria->add(PlayerTableMap::COL_NICKNAME, $this->nickname);
1274
        }
1275
        if ($this->isColumnModified(PlayerTableMap::COL_NICKNAME_STRIPPED)) {
1276
            $criteria->add(PlayerTableMap::COL_NICKNAME_STRIPPED, $this->nickname_stripped);
1277
        }
1278
        if ($this->isColumnModified(PlayerTableMap::COL_PATH)) {
1279
            $criteria->add(PlayerTableMap::COL_PATH, $this->path);
1280
        }
1281
        if ($this->isColumnModified(PlayerTableMap::COL_WINS)) {
1282
            $criteria->add(PlayerTableMap::COL_WINS, $this->wins);
1283
        }
1284
        if ($this->isColumnModified(PlayerTableMap::COL_ONLINE_TIME)) {
1285
            $criteria->add(PlayerTableMap::COL_ONLINE_TIME, $this->online_time);
1286
        }
1287
        if ($this->isColumnModified(PlayerTableMap::COL_LAST_ONLINE)) {
1288
            $criteria->add(PlayerTableMap::COL_LAST_ONLINE, $this->last_online);
1289
        }
1290
1291
        return $criteria;
1292
    }
1293
1294
    /**
1295
     * Builds a Criteria object containing the primary key for this object.
1296
     *
1297
     * Unlike buildCriteria() this method includes the primary key values regardless
1298
     * of whether or not they have been modified.
1299
     *
1300
     * @throws LogicException if no primary key is defined
1301
     *
1302
     * @return Criteria The Criteria object containing value(s) for primary key(s).
1303
     */
1304
    public function buildPkeyCriteria()
1305
    {
1306
        $criteria = ChildPlayerQuery::create();
1307
        $criteria->add(PlayerTableMap::COL_ID, $this->id);
1308
1309
        return $criteria;
1310
    }
1311
1312
    /**
1313
     * If the primary key is not null, return the hashcode of the
1314
     * primary key. Otherwise, return the hash code of the object.
1315
     *
1316
     * @return int Hashcode
1317
     */
1318 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...
1319
    {
1320
        $validPk = null !== $this->getId();
1321
1322
        $validPrimaryKeyFKs = 0;
1323
        $primaryKeyFKs = [];
1324
1325
        if ($validPk) {
1326
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
1327
        } elseif ($validPrimaryKeyFKs) {
1328
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
1329
        }
1330
1331
        return spl_object_hash($this);
1332
    }
1333
1334
    /**
1335
     * Returns the primary key for this object (row).
1336
     * @return int
1337
     */
1338
    public function getPrimaryKey()
1339
    {
1340
        return $this->getId();
1341
    }
1342
1343
    /**
1344
     * Generic method to set the primary key (id column).
1345
     *
1346
     * @param       int $key Primary key.
1347
     * @return void
1348
     */
1349
    public function setPrimaryKey($key)
1350
    {
1351
        $this->setId($key);
1352
    }
1353
1354
    /**
1355
     * Returns true if the primary key for this object is null.
1356
     * @return boolean
1357
     */
1358
    public function isPrimaryKeyNull()
1359
    {
1360
        return null === $this->getId();
1361
    }
1362
1363
    /**
1364
     * Sets contents of passed object to values from current object.
1365
     *
1366
     * If desired, this method can also make copies of all associated (fkey referrers)
1367
     * objects.
1368
     *
1369
     * @param      object $copyObj An object of \eXpansion\Framework\PlayersBundle\Model\Player (or compatible) type.
1370
     * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1371
     * @param      boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1372
     * @throws PropelException
1373
     */
1374
    public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1375
    {
1376
        $copyObj->setLogin($this->getLogin());
1377
        $copyObj->setNickname($this->getNickname());
1378
        $copyObj->setNicknameStripped($this->getNicknameStripped());
1379
        $copyObj->setPath($this->getPath());
1380
        $copyObj->setWins($this->getWins());
1381
        $copyObj->setOnlineTime($this->getOnlineTime());
1382
        $copyObj->setLastOnline($this->getLastOnline());
1383
1384
        if ($deepCopy) {
1385
            // important: temporarily setNew(false) because this affects the behavior of
1386
            // the getter/setter methods for fkey referrer objects.
1387
            $copyObj->setNew(false);
1388
1389
            foreach ($this->getRecords() as $relObj) {
1390
                if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
1391
                    $copyObj->addRecord($relObj->copy($deepCopy));
1392
                }
1393
            }
1394
1395
        } // if ($deepCopy)
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...
1396
1397
        if ($makeNew) {
1398
            $copyObj->setNew(true);
1399
            $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
1400
        }
1401
    }
1402
1403
    /**
1404
     * Makes a copy of this object that will be inserted as a new row in table when saved.
1405
     * It creates a new object filling in the simple attributes, but skipping any primary
1406
     * keys that are defined for the table.
1407
     *
1408
     * If desired, this method can also make copies of all associated (fkey referrers)
1409
     * objects.
1410
     *
1411
     * @param  boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1412
     * @return \eXpansion\Framework\PlayersBundle\Model\Player Clone of current object.
1413
     * @throws PropelException
1414
     */
1415 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...
1416
    {
1417
        // we use get_class(), because this might be a subclass
1418
        $clazz = get_class($this);
1419
        $copyObj = new $clazz();
1420
        $this->copyInto($copyObj, $deepCopy);
1421
1422
        return $copyObj;
1423
    }
1424
1425
1426
    /**
1427
     * Initializes a collection based on the name of a relation.
1428
     * Avoids crafting an 'init[$relationName]s' method name
1429
     * that wouldn't work when StandardEnglishPluralizer is used.
1430
     *
1431
     * @param      string $relationName The name of the relation to initialize
1432
     * @return void
1433
     */
1434
    public function initRelation($relationName)
1435
    {
1436
        if ('Record' == $relationName) {
1437
            return $this->initRecords();
1438
        }
1439
    }
1440
1441
    /**
1442
     * Clears out the collRecords collection
1443
     *
1444
     * This does not modify the database; however, it will remove any associated objects, causing
1445
     * them to be refetched by subsequent calls to accessor method.
1446
     *
1447
     * @return void
1448
     * @see        addRecords()
1449
     */
1450
    public function clearRecords()
1451
    {
1452
        $this->collRecords = null; // important to set this to NULL since that means it is uninitialized
1453
    }
1454
1455
    /**
1456
     * Reset is the collRecords collection loaded partially.
1457
     */
1458
    public function resetPartialRecords($v = true)
1459
    {
1460
        $this->collRecordsPartial = $v;
1461
    }
1462
1463
    /**
1464
     * Initializes the collRecords collection.
1465
     *
1466
     * By default this just sets the collRecords collection to an empty array (like clearcollRecords());
1467
     * however, you may wish to override this method in your stub class to provide setting appropriate
1468
     * to your application -- for example, setting the initial array to the values stored in database.
1469
     *
1470
     * @param      boolean $overrideExisting If set to true, the method call initializes
1471
     *                                        the collection even if it is not empty
1472
     *
1473
     * @return void
1474
     */
1475
    public function initRecords($overrideExisting = true)
1476
    {
1477
        if (null !== $this->collRecords && !$overrideExisting) {
1478
            return;
1479
        }
1480
1481
        $collectionClassName = RecordTableMap::getTableMap()->getCollectionClassName();
1482
1483
        $this->collRecords = new $collectionClassName;
1484
        $this->collRecords->setModel('\eXpansion\Bundle\LocalRecords\Model\Record');
1485
    }
1486
1487
    /**
1488
     * Gets an array of Record objects which contain a foreign key that references this object.
1489
     *
1490
     * If the $criteria is not null, it is used to always fetch the results from the database.
1491
     * Otherwise the results are fetched from the database the first time, then cached.
1492
     * Next time the same method is called without $criteria, the cached collection is returned.
1493
     * If this ChildPlayer is new, it will return
1494
     * an empty collection or the current collection; the criteria is ignored on a new object.
1495
     *
1496
     * @param      Criteria $criteria optional Criteria object to narrow the query
1497
     * @param      ConnectionInterface $con optional connection object
1498
     * @return ObjectCollection|Record[] List of Record objects
1499
     * @throws PropelException
1500
     */
1501
    public function getRecords(Criteria $criteria = null, ConnectionInterface $con = null)
1502
    {
1503
        $partial = $this->collRecordsPartial && !$this->isNew();
1504
        if (null === $this->collRecords || null !== $criteria  || $partial) {
1505
            if ($this->isNew() && null === $this->collRecords) {
1506
                // return empty collection
1507
                $this->initRecords();
1508
            } else {
1509
                $collRecords = RecordQuery::create(null, $criteria)
1510
                    ->filterByPlayer($this)
0 ignored issues
show
Documentation introduced by
$this is of type this<eXpansion\Framework...ndle\Model\Base\Player>, but the function expects a object<eXpansion\Framewo...ction\ObjectCollection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1511
                    ->find($con);
0 ignored issues
show
Bug introduced by
It seems like $con defined by parameter $con on line 1501 can be null; however, eXpansion\Bundle\LocalRe...ase\RecordQuery::find() does not accept null, maybe add an additional type check?

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

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

function notNullable(stdClass $x) { }

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

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

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
1512
1513
                if (null !== $criteria) {
1514
                    if (false !== $this->collRecordsPartial && count($collRecords)) {
1515
                        $this->initRecords(false);
1516
1517
                        foreach ($collRecords as $obj) {
1518
                            if (false == $this->collRecords->contains($obj)) {
1519
                                $this->collRecords->append($obj);
1520
                            }
1521
                        }
1522
1523
                        $this->collRecordsPartial = true;
1524
                    }
1525
1526
                    return $collRecords;
1527
                }
1528
1529
                if ($partial && $this->collRecords) {
1530
                    foreach ($this->collRecords as $obj) {
1531
                        if ($obj->isNew()) {
1532
                            $collRecords[] = $obj;
1533
                        }
1534
                    }
1535
                }
1536
1537
                $this->collRecords = $collRecords;
1538
                $this->collRecordsPartial = false;
1539
            }
1540
        }
1541
1542
        return $this->collRecords;
1543
    }
1544
1545
    /**
1546
     * Sets a collection of Record objects related by a one-to-many relationship
1547
     * to the current object.
1548
     * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1549
     * and new objects from the given Propel collection.
1550
     *
1551
     * @param      Collection $records A Propel collection.
1552
     * @param      ConnectionInterface $con Optional connection object
1553
     * @return $this|ChildPlayer The current object (for fluent API support)
1554
     */
1555
    public function setRecords(Collection $records, ConnectionInterface $con = null)
1556
    {
1557
        /** @var Record[] $recordsToDelete */
1558
        $recordsToDelete = $this->getRecords(new Criteria(), $con)->diff($records);
1559
1560
1561
        $this->recordsScheduledForDeletion = $recordsToDelete;
1562
1563
        foreach ($recordsToDelete as $recordRemoved) {
1564
            $recordRemoved->setPlayer(null);
1565
        }
1566
1567
        $this->collRecords = null;
1568
        foreach ($records as $record) {
1569
            $this->addRecord($record);
1570
        }
1571
1572
        $this->collRecords = $records;
0 ignored issues
show
Documentation Bug introduced by
It seems like $records of type object<Propel\Runtime\Collection\Collection> is incompatible with the declared type object<Propel\Runtime\Co...lRecords\Model\Record>> of property $collRecords.

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

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

Loading history...
1573
        $this->collRecordsPartial = false;
1574
1575
        return $this;
1576
    }
1577
1578
    /**
1579
     * Returns the number of related BaseRecord objects.
1580
     *
1581
     * @param      Criteria $criteria
1582
     * @param      boolean $distinct
1583
     * @param      ConnectionInterface $con
1584
     * @return int             Count of related BaseRecord objects.
1585
     * @throws PropelException
1586
     */
1587
    public function countRecords(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
1588
    {
1589
        $partial = $this->collRecordsPartial && !$this->isNew();
1590
        if (null === $this->collRecords || null !== $criteria || $partial) {
1591
            if ($this->isNew() && null === $this->collRecords) {
1592
                return 0;
1593
            }
1594
1595
            if ($partial && !$criteria) {
1596
                return count($this->getRecords());
1597
            }
1598
1599
            $query = RecordQuery::create(null, $criteria);
1600
            if ($distinct) {
1601
                $query->distinct();
1602
            }
1603
1604
            return $query
1605
                ->filterByPlayer($this)
0 ignored issues
show
Documentation introduced by
$this is of type this<eXpansion\Framework...ndle\Model\Base\Player>, but the function expects a object<eXpansion\Framewo...ction\ObjectCollection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1606
                ->count($con);
1607
        }
1608
1609
        return count($this->collRecords);
1610
    }
1611
1612
    /**
1613
     * Method called to associate a Record object to this object
1614
     * through the Record foreign key attribute.
1615
     *
1616
     * @param  Record $l Record
1617
     * @return $this|\eXpansion\Framework\PlayersBundle\Model\Player The current object (for fluent API support)
1618
     */
1619
    public function addRecord(Record $l)
1620
    {
1621
        if ($this->collRecords === null) {
1622
            $this->initRecords();
1623
            $this->collRecordsPartial = true;
1624
        }
1625
1626
        if (!$this->collRecords->contains($l)) {
1627
            $this->doAddRecord($l);
1628
1629
            if ($this->recordsScheduledForDeletion and $this->recordsScheduledForDeletion->contains($l)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
1630
                $this->recordsScheduledForDeletion->remove($this->recordsScheduledForDeletion->search($l));
1631
            }
1632
        }
1633
1634
        return $this;
1635
    }
1636
1637
    /**
1638
     * @param Record $record The Record object to add.
1639
     */
1640
    protected function doAddRecord(Record $record)
1641
    {
1642
        $this->collRecords[]= $record;
1643
        $record->setPlayer($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<eXpansion\Framework...ndle\Model\Base\Player>, but the function expects a null|object<eXpansion\Fr...ersBundle\Model\Player>.

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...
1644
    }
1645
1646
    /**
1647
     * @param  Record $record The Record object to remove.
1648
     * @return $this|ChildPlayer The current object (for fluent API support)
1649
     */
1650
    public function removeRecord(Record $record)
1651
    {
1652
        if ($this->getRecords()->contains($record)) {
1653
            $pos = $this->collRecords->search($record);
1654
            $this->collRecords->remove($pos);
1655
            if (null === $this->recordsScheduledForDeletion) {
1656
                $this->recordsScheduledForDeletion = clone $this->collRecords;
1657
                $this->recordsScheduledForDeletion->clear();
1658
            }
1659
            $this->recordsScheduledForDeletion[]= $record;
1660
            $record->setPlayer(null);
1661
        }
1662
1663
        return $this;
1664
    }
1665
1666
    /**
1667
     * Clears the current object, sets all attributes to their default values and removes
1668
     * outgoing references as well as back-references (from other objects to this one. Results probably in a database
1669
     * change of those foreign objects when you call `save` there).
1670
     */
1671
    public function clear()
1672
    {
1673
        $this->id = null;
1674
        $this->login = null;
1675
        $this->nickname = null;
1676
        $this->nickname_stripped = null;
1677
        $this->path = null;
1678
        $this->wins = null;
1679
        $this->online_time = null;
1680
        $this->last_online = null;
1681
        $this->alreadyInSave = false;
1682
        $this->clearAllReferences();
1683
        $this->resetModified();
1684
        $this->setNew(true);
1685
        $this->setDeleted(false);
1686
    }
1687
1688
    /**
1689
     * Resets all references and back-references to other model objects or collections of model objects.
1690
     *
1691
     * This method is used to reset all php object references (not the actual reference in the database).
1692
     * Necessary for object serialisation.
1693
     *
1694
     * @param      boolean $deep Whether to also clear the references on all referrer objects.
1695
     */
1696
    public function clearAllReferences($deep = false)
1697
    {
1698
        if ($deep) {
1699
            if ($this->collRecords) {
1700
                foreach ($this->collRecords as $o) {
1701
                    $o->clearAllReferences($deep);
1702
                }
1703
            }
1704
        } // 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...
1705
1706
        $this->collRecords = null;
1707
    }
1708
1709
    /**
1710
     * Return the string representation of this object
1711
     *
1712
     * @return string The value of the 'login' column
1713
     */
1714
    public function __toString()
1715
    {
1716
        return (string) $this->getLogin();
1717
    }
1718
1719
    /**
1720
     * Code to be run before persisting the object
1721
     * @param  ConnectionInterface $con
1722
     * @return boolean
1723
     */
1724
    public function preSave(ConnectionInterface $con = null)
1725
    {
1726
        if (is_callable('parent::preSave')) {
1727
            return parent::preSave($con);
1728
        }
1729
        return true;
1730
    }
1731
1732
    /**
1733
     * Code to be run after persisting the object
1734
     * @param ConnectionInterface $con
1735
     */
1736
    public function postSave(ConnectionInterface $con = null)
1737
    {
1738
        if (is_callable('parent::postSave')) {
1739
            parent::postSave($con);
1740
        }
1741
    }
1742
1743
    /**
1744
     * Code to be run before inserting to database
1745
     * @param  ConnectionInterface $con
1746
     * @return boolean
1747
     */
1748
    public function preInsert(ConnectionInterface $con = null)
1749
    {
1750
        if (is_callable('parent::preInsert')) {
1751
            return parent::preInsert($con);
1752
        }
1753
        return true;
1754
    }
1755
1756
    /**
1757
     * Code to be run after inserting to database
1758
     * @param ConnectionInterface $con
1759
     */
1760
    public function postInsert(ConnectionInterface $con = null)
1761
    {
1762
        if (is_callable('parent::postInsert')) {
1763
            parent::postInsert($con);
1764
        }
1765
    }
1766
1767
    /**
1768
     * Code to be run before updating the object in database
1769
     * @param  ConnectionInterface $con
1770
     * @return boolean
1771
     */
1772
    public function preUpdate(ConnectionInterface $con = null)
1773
    {
1774
        if (is_callable('parent::preUpdate')) {
1775
            return parent::preUpdate($con);
1776
        }
1777
        return true;
1778
    }
1779
1780
    /**
1781
     * Code to be run after updating the object in database
1782
     * @param ConnectionInterface $con
1783
     */
1784
    public function postUpdate(ConnectionInterface $con = null)
1785
    {
1786
        if (is_callable('parent::postUpdate')) {
1787
            parent::postUpdate($con);
1788
        }
1789
    }
1790
1791
    /**
1792
     * Code to be run before deleting the object in database
1793
     * @param  ConnectionInterface $con
1794
     * @return boolean
1795
     */
1796
    public function preDelete(ConnectionInterface $con = null)
1797
    {
1798
        if (is_callable('parent::preDelete')) {
1799
            return parent::preDelete($con);
1800
        }
1801
        return true;
1802
    }
1803
1804
    /**
1805
     * Code to be run after deleting the object in database
1806
     * @param ConnectionInterface $con
1807
     */
1808
    public function postDelete(ConnectionInterface $con = null)
1809
    {
1810
        if (is_callable('parent::postDelete')) {
1811
            parent::postDelete($con);
1812
        }
1813
    }
1814
1815
1816
    /**
1817
     * Derived method to catches calls to undefined methods.
1818
     *
1819
     * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.).
1820
     * Allows to define default __call() behavior if you overwrite __call()
1821
     *
1822
     * @param string $name
1823
     * @param mixed  $params
1824
     *
1825
     * @return array|string
1826
     */
1827 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...
1828
    {
1829
        if (0 === strpos($name, 'get')) {
1830
            $virtualColumn = substr($name, 3);
1831
            if ($this->hasVirtualColumn($virtualColumn)) {
1832
                return $this->getVirtualColumn($virtualColumn);
1833
            }
1834
1835
            $virtualColumn = lcfirst($virtualColumn);
1836
            if ($this->hasVirtualColumn($virtualColumn)) {
1837
                return $this->getVirtualColumn($virtualColumn);
1838
            }
1839
        }
1840
1841
        if (0 === strpos($name, 'from')) {
1842
            $format = substr($name, 4);
1843
1844
            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)); (eXpansion\Framework\Play...undle\Model\Base\Player) is incompatible with the return type documented by eXpansion\Framework\Play...del\Base\Player::__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...
1845
        }
1846
1847
        if (0 === strpos($name, 'to')) {
1848
            $format = substr($name, 2);
1849
            $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true;
1850
1851
            return $this->exportTo($format, $includeLazyLoadColumns);
1852
        }
1853
1854
        throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name));
1855
    }
1856
1857
}
1858