| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace app\controllers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use app\actions\SubmitFormAction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use app\backend\actions\PropertyHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use app\components\search\SearchEvent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use app\models\Form; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use app\models\Search; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use app\modules\core\components\MailComponent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use app\modules\shop\models\Product; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use app\modules\seo\behaviors\MetaBehavior; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Yii; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use yii\helpers\Url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use yii\web\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use yii\web\Response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class DefaultController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @inheritdoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function actions() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             'error' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 'class' => 'app\actions\ErrorAction', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             'captcha' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 'class' => 'yii\captcha\CaptchaAction', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             'submit-form' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 'class' => SubmitFormAction::className(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | //            'property-handler' => [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | //                'class' => PropertyHandler::className(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | //                'modelName' => Form::className() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | //            ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 43 |  | View Code Duplication |     public function behaviors() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             'verbs' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 'class' => \yii\filters\VerbFilter::className(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 'actions' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                     'submit-form' => ['post'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     public function actionIndex() | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         return $this->render('index'); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     public function actionSearch() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $model = new Search(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $model->load(Yii::$app->request->get()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         return $this->render( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             'search', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 'model' => $model, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @param $term | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @return string JSON | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     public function actionAutoCompleteSearch($term) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         Yii::$app->response->format = Response::FORMAT_JSON; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $search = new Search(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $search->q = $term; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $search->on(Search::QUERY_SEARCH_PRODUCTS_BY_DESCRIPTION, function (SearchEvent $event) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             $event->setFunctionSearch(function ($activeQuery) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 $activeQuery->limit(Yii::$app->getModule('core')->autoCompleteResultsCount); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                 return Product::find() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                     ->select(['id', 'name', 'main_category_id', 'slug', 'sku']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                     ->where(['id' => $activeQuery->all()]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                     ->all(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $products = $search->searchProductsByDescription(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $result = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         foreach ($products as $product) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             /** @var Product $product */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             $result[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 'id' => $product->id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                 'name' => $product->name, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                 'url' => Url::toRoute( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                     [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                         '@product', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                         'model' => $product, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                         'category_group_id' => $product->getMainCategory()->category_group_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                     ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                     true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 111 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |  | 
            
                        
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.