AppController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actionGenerateSitemap() 0 15 2
A actionClearTable() 0 8 2
1
<?php
2
3
namespace app\commands;
4
5
use Yii;
6
use yii2mod\cms\models\CmsModel;
7
use yii2tech\sitemap\File;
8
9
/**
10
 * Class AppController
11
 *
12
 * ```php
13
 * php yii app/generate-sitemap - Sitemap composing
14
 * php yii app/clear-table User - Delete all data from specific table
15
 * ```
16
 *
17
 * @author Igor Chepurnoy <[email protected]>
18
 *
19
 * @since 1.0
20
 */
21
class AppController extends BaseController
22
{
23
    /**
24
     * Generate sitemap
25
     */
26
    public function actionGenerateSitemap(): int
27
    {
28
        $siteMapFile = new File();
29
30
        $siteMapFile->writeUrl(['site/index'], ['priority' => '0.9']);
31
        $siteMapFile->writeUrl(['site/contact']);
32
        $pages = CmsModel::find()->enabled()->all();
33
        foreach ($pages as $page) {
34
            $siteMapFile->writeUrl([$page->url]);
35
        }
36
37
        $siteMapFile->close();
38
39
        return self::EXIT_CODE_NORMAL;
0 ignored issues
show
Deprecated Code introduced by
The constant yii\console\Controller::EXIT_CODE_NORMAL has been deprecated with message: since 2.0.13. Use [[ExitCode::OK]] instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
40
    }
41
42
    /**
43
     * Delete all data from specific table
44
     *
45
     * @param $tableName
46
     *
47
     * @throws \yii\db\Exception
48
     *
49
     * @return int
50
     */
51
    public function actionClearTable($tableName): int
52
    {
53
        if ($this->confirm(Yii::t('app', 'Are you sure you want to clear this table?'))) {
54
            Yii::$app->db->createCommand()->delete($tableName)->execute();
55
        }
56
57
        return self::EXIT_CODE_NORMAL;
0 ignored issues
show
Deprecated Code introduced by
The constant yii\console\Controller::EXIT_CODE_NORMAL has been deprecated with message: since 2.0.13. Use [[ExitCode::OK]] instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
58
    }
59
}
60