Passed
Push — master ( 11319f...d27303 )
by Sergey
02:38
created

ManagerController::sharingPreview()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Lionix\SeoManager;
4
5
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\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...
6
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request 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...
7
use Illuminate\Support\Facades\Input;
8
use Illuminate\Support\Facades\Schema;
9
use Lionix\SeoManager\Models\SeoManager as SeoManagerModel;
10
use Lionix\SeoManager\Models\Translate;
11
use Lionix\SeoManager\Traits\SeoManagerTrait;
12
13
class ManagerController extends Controller
14
{
15
    use SeoManagerTrait;
16
17
    protected $locale;
18
19
    public function __construct()
20
    {
21
        if(Input::get('locale')){
22
            app()->setLocale(Input::get('locale'));
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

22
            /** @scrutinizer ignore-call */ 
23
            app()->setLocale(Input::get('locale'));
Loading history...
23
            $this->locale = app()->getLocale();
24
        }
25
}
26
    /**
27
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
0 ignored issues
show
Bug introduced by
The type Illuminate\View\View 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...
28
     */
29
    public function index()
30
    {
31
        return view('seo-manager::index');
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

31
        return /** @scrutinizer ignore-call */ view('seo-manager::index');
Loading history...
32
    }
33
34
    /**
35
     * @return \Illuminate\Http\JsonResponse
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\JsonResponse 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...
36
     */
37
    public function getRoutes()
38
    {
39
        $routes = SeoManagerModel::all();
40
        return response()->json(['routes' => $routes]);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

40
        return /** @scrutinizer ignore-call */ response()->json(['routes' => $routes]);
Loading history...
41
    }
42
43
    /**
44
     * @return \Illuminate\Http\JsonResponse
45
     */
46
    public function getModels()
47
    {
48
        try {
49
            $models = $this->getAllModels();
50
            return response()->json(['models' => $models]);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

50
            return /** @scrutinizer ignore-call */ response()->json(['models' => $models]);
Loading history...
51
        } catch (\Exception $exception) {
52
            return response()->json(['status' => false, 'message' => $exception->getMessage()]);
53
        }
54
    }
55
56
    /**
57
     * @param Request $request
58
     * @return \Illuminate\Http\JsonResponse
59
     * @throws \Throwable
60
     */
61
    public function getModelColumns(Request $request)
62
    {
63
        try {
64
            $model = $request->get('model');
65
            $columns = $this->getColumns($model);
66
            return response()->json(['columns' => $columns]);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

66
            return /** @scrutinizer ignore-call */ response()->json(['columns' => $columns]);
Loading history...
67
        } catch (\Exception $exception) {
68
            return response()->json(['status' => false, 'message' => $exception->getMessage()]);
69
        }
70
    }
71
72
    /**
73
     * @param Request $request
74
     * @return \Illuminate\Http\JsonResponse
75
     */
76
    public function storeData(Request $request)
77
    {
78
        $allowedColumns = Schema::getColumnListing(config('seo-manager.database.table'));
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

78
        $allowedColumns = Schema::getColumnListing(/** @scrutinizer ignore-call */ config('seo-manager.database.table'));
Loading history...
79
        try {
80
            $id = $request->get('id');
81
            $type = $request->get('type');
82
            $seoManager = SeoManagerModel::find($id);
83
            if (in_array($type, $allowedColumns)) {
84
                $data = $request->get($type);
85
                if($type != 'mapping' && $this->locale !== config('seo-manager.locale')){
86
                    $translate = $seoManager->translation()->where('locale', $this->locale)->first();
87
                    if(!$translate){
88
                        $newInst = new Translate();
89
                        $newInst->locale = $this->locale;
90
                        $translate = $seoManager->translation()->save($newInst);
91
                    }
92
                    $translate->$type = $data;
93
                    $translate->save();
94
                }else{
95
                    $seoManager->$type = $data;
96
                    $seoManager->save();
97
                }
98
            }
99
            return response()->json([$type => $seoManager->$type]);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

99
            return /** @scrutinizer ignore-call */ response()->json([$type => $seoManager->$type]);
Loading history...
100
        } catch (\Exception $exception) {
101
            return response()->json(['status' => false, 'message' => $exception->getMessage()]);
102
        }
103
    }
104
105
    /**
106
     * @param Request $request
107
     * @return \Illuminate\Http\JsonResponse
108
     */
109
    public function getExampleTitle(Request $request)
110
    {
111
        try {
112
            $manager = SeoManagerModel::find($request->id);
113
            $titles = $request->get('title_dynamic');
114
            $exampleTitle = $this->getDynamicTitle($titles, $manager);
115
            return response()->json(['example_title' => $exampleTitle]);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

115
            return /** @scrutinizer ignore-call */ response()->json(['example_title' => $exampleTitle]);
Loading history...
116
        } catch (\Exception $exception) {
117
            return response()->json(['status' => false, 'message' => $exception->getMessage()]);
118
        }
119
    }
120
121
    /**
122
     * @param Request $request
123
     * @return \Illuminate\Http\JsonResponse
124
     */
125
    public function deleteRoute(Request $request)
126
    {
127
        try {
128
            SeoManagerModel::destroy($request->id);
129
            return response()->json(['deleted' => true]);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

129
            return /** @scrutinizer ignore-call */ response()->json(['deleted' => true]);
Loading history...
130
        } catch (\Exception $exception) {
131
            return response()->json(['status' => false, 'message' => $exception->getMessage()]);
132
        }
133
    }
134
135
    /**
136
     * @param Request $request
137
     * @return array|null
138
     */
139
    public function sharingPreview(Request $request)
140
    {
141
        $id = $request->get('id');
142
        $seoManager = SeoManagerModel::find($id);
143
        if(is_null($seoManager)){
144
            return null;
145
        }
146
        $ogData = $this->getOgData($seoManager, null);
147
        return response()->json(['og_data' => $ogData]);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

147
        return /** @scrutinizer ignore-call */ response()->json(['og_data' => $ogData]);
Loading history...
148
    }
149
}
150