Completed
Pull Request — master (#18)
by ARCANEDEV
02:59
created

FormRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 4 1
rules() 0 1 ?
A prepareForValidation() 0 6 2
1
<?php namespace Arcanedev\Support\Http;
2
3
use Illuminate\Foundation\Http\FormRequest as BaseFormRequest;
4
5
/**
6
 * Class     FormRequest
7
 *
8
 * @package  Arcanedev\Support
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
abstract class FormRequest extends BaseFormRequest
12
{
13
    /* -----------------------------------------------------------------
14
     |  Main Methods
15
     | -----------------------------------------------------------------
16
     */
17
18
    /**
19
     * Determine if the user is authorized to make this request.
20
     *
21
     * @return bool
22
     */
23
    public function authorize()
24
    {
25
        return false;
26
    }
27
28
    /**
29
     * Get the validation rules that apply to the request.
30
     *
31
     * @return array
32
     */
33
    abstract public function rules();
34
35
    /**
36
     * Prepare the data for validation.
37
     */
38 6
    protected function prepareForValidation()
39
    {
40 6
        if (method_exists($this, 'sanitize')) {
41 6
            $this->merge($this->sanitize());
0 ignored issues
show
Documentation Bug introduced by
The method sanitize does not exist on object<Arcanedev\Support\Http\FormRequest>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
42 2
        }
43 6
    }
44
}
45