Completed
Push — master ( bc825a...1aba9a )
by William
06:03
created

CleanOldNotifsShell::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
/* vim: set expandtab sw=4 ts=4 sts=4: */
4
/**
5
 * Clean Old Notifications Shell.
6
 *
7
 * phpMyAdmin Error reporting server
8
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
9
 *
10
 * Licensed under The MIT License
11
 * For full copyright and license information, please see the LICENSE.txt
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
15
 * @license   https://opensource.org/licenses/mit-license.php MIT License
16
 *
17
 * @see      https://www.phpmyadmin.net/
18
 */
19
20
namespace App\Shell;
21
22
use Cake\Console\Shell;
23
use Cake\Log\Log;
24
25
/**
26
 * Clean old Notifications shell.
27
 */
28
class CleanOldNotifsShell extends Shell
29
{
30 1
    public function initialize()
31
    {
32 1
        parent::initialize();
33 1
        $this->loadModel('Notifications');
34 1
    }
35
36 1
    public function main()
37
    {
38 1
        $XTime = time() - 60 * 24 * 3600;
39 1
        $conditions = ['Notifications.created <' => date('Y-m-d H:i:s', $XTime)];
40
41 1
        if ($this->Notifications->find('all', ['conditions' => $conditions])->count() === 0) {
0 ignored issues
show
Bug Best Practice introduced by
The property Notifications does not exist on App\Shell\CleanOldNotifsShell. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method find() does not exist on Cake\Console\Shell. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        if ($this->Notifications->/** @scrutinizer ignore-call */ find('all', ['conditions' => $conditions])->count() === 0) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
            // Check if there are any notifications to delete
43 1
            Log::write(
44 1
                'info',
45 1
                'No notifications found for deleting!',
46 1
                'cron_jobs'
47
            );
48 1
        } elseif ($this->Notifications->deleteAll($conditions)) {
0 ignored issues
show
Bug introduced by
The method deleteAll() does not exist on Cake\Console\Shell. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
        } elseif ($this->Notifications->/** @scrutinizer ignore-call */ deleteAll($conditions)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
            // Try deleting the matched records
50 1
            Log::write(
51 1
                'info',
52 1
                'Old notifications deleted successfully!',
53 1
                'cron_jobs'
54
            );
55
        } else {
56
            // If NOT successful, print out an error message
57
            Log::write(
58
                'error',
59
                'Deleting old notifications failed!',
60
                'cron_jobs'
61
            );
62
        }
63 1
    }
64
}
65