| Conditions | 2 |
| Paths | 2 |
| Total Lines | 18 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 25 | public static function cleanup() |
||
| 26 | { |
||
| 27 | // run cleanup with chance |
||
| 28 | if (mt_rand(0, 100) > static::RAND_CHANCE) { |
||
| 29 | return; |
||
| 30 | } |
||
| 31 | |||
| 32 | // get session max lifetime |
||
| 33 | $lifetime = App::$Session->getMetadataBag()->getLifetime(); |
||
| 34 | // multiple x2 to prevent any shits ;D |
||
| 35 | $lifetime *= 2; |
||
| 36 | // current unixtime minus lifetime |
||
| 37 | $timestamp = time() - $lifetime; |
||
| 38 | $sqlFormatedTime = Date::convertToDatetime($timestamp, Date::FORMAT_SQL_DATE); |
||
| 39 | |||
| 40 | /// remove oldest rows |
||
| 41 | self::where('created_at', '<=', $sqlFormatedTime)->delete(); |
||
| 42 | } |
||
| 43 | |||
| 54 | } |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: