ModPreload   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 22 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 1 Features 2
Metric Value
wmc 3
c 2
b 1
f 2
lcom 0
cbo 5
dl 11
loc 50
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B play() 11 35 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * ModPreload
4
 *
5
 * グループ情報変更処理を実現するためのクラス
6
 *
7
 * @package           risoluto
8
 * @author            Risoluto Developers
9
 * @license           http://opensource.org/licenses/bsd-license.php new BSD license
10
 * @copyright     (C) 2008-2015 Risoluto Developers / All Rights Reserved.
11
 */
12
13
//------------------------------------------------------//
14
// 名前空間の定義
15
//------------------------------------------------------//
16
namespace RisolutoApps\Admin\GroupMng;
17
18
//------------------------------------------------------//
19
// クラス定義
20
//------------------------------------------------------//
21
class ModPreload extends \Risoluto\RisolutoControllerBase implements \Risoluto\RisolutoControllerInterface
22
{
23
    /**
24
     * play()
25
     *
26
     * 主処理を行う
27
     *
28
     * @access    public
29
     *
30
     * @param     void
31
     *
32
     * @return    void    なし
33
     * @throws    \Exception 必須な情報が渡されていないか情報が取得できない場合はThrow
34
     */
35
    public function play()
36
    {
37
        // セッションをスタート
38
        $sess = new \Risoluto\Session();
39
        $sess->start();
40
41
        // 共通処理クラスを呼び出し
42
        $common = new \RisolutoApps\Admin\AdminCommon;
43
        /** @noinspection PhpUnusedLocalVariableInspection */
44
        $detail = $common->loginCheck( $sess, true );
0 ignored issues
show
Unused Code introduced by Yuta Hayakawa
$detail is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
45
46
        $param = $this->getParam();
47 View Code Duplication
        if (is_numeric( $param[ 0 ] )) {
0 ignored issues
show
Duplication introduced by Yuta Hayakawa
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...
48
            // 引数値がセットされていれば、それを元に登録情報を呼び出す
49
            $target = \Risoluto\Auth::callProviderMethod( 'showGroupByNo', [ 'no' => $param[ 0 ] ] );
50
            if (empty( $target )) {
51
                // 情報が取得できなかった場合も例外をThrow
52
                Throw new \Exception( 'Cannot load group data' );
53
            }
54
        } else {
55
            // 指定されていなければ例外をThrowする
56
            Throw new \Exception( 'Require args not found' );
57
        }
58
59
        // 情報が取得できたら整形してセッションに保存、入力画面へ遷移する
60
        $getVals[ 'entered' ] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by Yuta Hayakawa
$getVals was never initialized. Although not strictly required by PHP, it is generally a good practice to add $getVals = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
61
            'no' => $target[ 0 ][ 'no' ],
62
            'groupid' => $target[ 0 ][ 'groupid' ],
63
            'groupname' => $target[ 0 ][ 'groupname' ],
64
            'status' => $target[ 0 ][ 'status' ]
65
        ];
66
        $sess->store( 'form', $getVals );
67
        \Risoluto\Url::redirectTo( 'Admin_GroupMng_ModEntry' );
68
        exit;
69
    }
70
}