Completed
Push — develop ( 756067...9eed34 )
by Abdelrahman
01:39
created

ContactsController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Contacts\Http\Controllers\Managerarea;
6
7
use Illuminate\Http\Request;
8
use Rinvex\Contacts\Contracts\ContactContract;
9
use Cortex\Foundation\DataTables\LogsDataTable;
10
use Cortex\Contacts\DataTables\Managerarea\ContactsDataTable;
11
use Cortex\Foundation\Http\Controllers\AuthorizedController;
12
use Cortex\Contacts\Http\Requests\Managerarea\ContactFormRequest;
13
14
class ContactsController extends AuthorizedController
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected $resource = 'contacts';
20
21
    /**
22
     * Display a listing of the resource.
23
     *
24
     * @param \Cortex\Contacts\DataTables\Managerarea\ContactsDataTable $contactsDataTable
25
     *
26
     * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
27
     */
28
    public function index(ContactsDataTable $contactsDataTable)
29
    {
30
        return $contactsDataTable->with([
31
            'id' => 'cortex-contacts',
32
            'phrase' => trans('cortex/contacts::common.contacts'),
33
        ])->render('cortex/tenants::managerarea.pages.datatable');
34
    }
35
36
    /**
37
     * Display a listing of the resource logs.
38
     *
39
     * @param \Rinvex\Contacts\Contracts\ContactContract  $category
0 ignored issues
show
Bug introduced by
There is no parameter named $category. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
40
     * @param \Cortex\Foundation\DataTables\LogsDataTable $logsDataTable
41
     *
42
     * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
43
     */
44
    public function logs(ContactContract $contact, LogsDataTable $logsDataTable)
45
    {
46
        return $logsDataTable->with([
47
            'tab' => 'logs',
48
            'type' => 'contacts',
49
            'resource' => $contact,
50
            'id' => 'cortex-contacts-logs',
51
            'phrase' => trans('cortex/contacts::common.contacts'),
52
        ])->render('cortex/tenants::managerarea.pages.datatable-tab');
53
    }
54
55
    /**
56
     * Store a newly created resource in storage.
57
     *
58
     * @param \Cortex\Contacts\Http\Requests\Managerarea\ContactFormRequest $request
59
     *
60
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...inate\Http\JsonResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
61
     */
62
    public function store(ContactFormRequest $request)
63
    {
64
        return $this->process($request, app('rinvex.contacts.contact'));
65
    }
66
67
    /**
68
     * Update the given resource in storage.
69
     *
70
     * @param \Cortex\Contacts\Http\Requests\Managerarea\ContactFormRequest $request
71
     * @param \Rinvex\Contacts\Contracts\ContactContract                   $contact
72
     *
73
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...inate\Http\JsonResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
74
     */
75
    public function update(ContactFormRequest $request, ContactContract $contact)
76
    {
77
        return $this->process($request, $contact);
78
    }
79
80
    /**
81
     * Delete the given resource from storage.
82
     *
83
     * @param \Rinvex\Contacts\Contracts\ContactContract $contact
84
     *
85
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...inate\Http\JsonResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
86
     */
87
    public function delete(ContactContract $contact)
88
    {
89
        $contact->delete();
90
91
        return intend([
92
            'url' => route('managerarea.contacts.index'),
93
            'with' => ['warning' => trans('cortex/contacts::messages.contact.deleted', ['slug' => $contact->slug])],
0 ignored issues
show
Bug introduced by
Accessing slug on the interface Rinvex\Contacts\Contracts\ContactContract suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
94
        ]);
95
    }
96
97
    /**
98
     * Show the form for create/update of the given resource.
99
     *
100
     * @param \Rinvex\Contacts\Contracts\ContactContract $contact
101
     *
102
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
103
     */
104
    public function form(ContactContract $contact)
105
    {
106
        $countries = countries();
107
        $languages = collect(languages())->pluck('name', 'iso_639_1');
108
        $sources = app('rinvex.contacts.contact')->distinct()->get(['source'])->pluck('source', 'source')->toArray();
109
        $methods = app('rinvex.contacts.contact')->distinct()->get(['method'])->pluck('method', 'method')->toArray();
110
        $genders = ['m' => trans('cortex/contacts::common.male'), 'f' => trans('cortex/contacts::common.female')];
111
112
        return view('cortex/contacts::managerarea.forms.contact', compact('contact', 'genders', 'countries', 'languages', 'sources', 'methods'));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 145 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
113
    }
114
115
    /**
116
     * Process the form for store/update of the given resource.
117
     *
118
     * @param \Illuminate\Http\Request                   $request
119
     * @param \Rinvex\Contacts\Contracts\ContactContract $contact
120
     *
121
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...inate\Http\JsonResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
122
     */
123
    protected function process(Request $request, ContactContract $contact)
124
    {
125
        // Prepare required input fields
126
        $data = $request->all();
127
128
        // Save contact
129
        $contact->fill($data)->save();
130
131
        return intend([
132
            'url' => route('managerarea.contacts.index'),
133
            'with' => ['success' => trans('cortex/contacts::messages.contact.saved', ['slug' => $contact->slug])],
0 ignored issues
show
Bug introduced by
Accessing slug on the interface Rinvex\Contacts\Contracts\ContactContract suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
134
        ]);
135
    }
136
}
137