Passed
Push — v1 ( 0f87a2...543469 )
by Andrew
08:17 queued 04:56
created

SamplesController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 20
dl 0
loc 57
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A options() 0 4 1
A actionTrim() 0 18 1
1
<?php
2
/**
3
 * Webperf plugin for Craft CMS 3.x
4
 *
5
 * Monitor the performance of your webpages through real-world user timing data
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2019 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\webperf\console\controllers;
12
13
use nystudio107\webperf\Webperf;
14
15
use Craft;
0 ignored issues
show
Bug introduced by
The type Craft was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use yii\console\Controller;
0 ignored issues
show
Bug introduced by
The type yii\console\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
19
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 4
Loading history...
20
 * @package   Webperf
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
21
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 5
Loading history...
22
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
23
class SamplesController extends Controller
24
{
25
    // Public Properties
26
    // =========================================================================
27
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var null|int
30
     */
31
    public $limit;
32
33
    // Protected Properties
34
    // =========================================================================
35
36
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
37
     * @var    bool|array
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 4
Loading history...
38
     */
39
    protected $allowAnonymous = [
40
    ];
41
42
    // Public Methods
43
    // =========================================================================
44
45
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
46
     * @param string $actionID
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
47
     *
48
     * @return array|string[]
49
     */
50
    public function options($actionID): array
51
    {
52
        return [
53
            'limit',
54
        ];
55
    }
56
57
    /**
58
     * Trim the Webperf Data Samples and Error Samples database tables
59
     *
60
     * @return int
61
     */
62
    public function actionTrim(): int
63
    {
64
        echo Craft::t('webperf', 'Trimming data samples').PHP_EOL;
65
        $affectedRows = Webperf::$plugin->dataSamples->trimDataSamples($this->limit);
66
        echo Craft::t(
67
            'webperf',
68
            'Trimmed {rows} from webperf_data_samples table',
69
            ['rows' => $affectedRows]
70
        ).PHP_EOL;
71
        echo Craft::t('webperf', 'Trimming error samples').PHP_EOL;
72
        $affectedRows = Webperf::$plugin->errorSamples->trimErrorSamples($this->limit);
73
        echo Craft::t(
74
            'webperf',
75
            'Trimmed {rows} from webperf_error_samples table',
76
            ['rows' => $affectedRows]
77
        ).PHP_EOL;
78
79
        return 0;
80
    }
81
}
82