Completed
Push — master ( 085d8e...d8e1df )
by Razon
09:39 queued 06:44
created

Form   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 28
rs 10
ccs 5
cts 9
cp 0.5556

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 4
1
<?php
2
namespace App\Form;
3
4
use yii\base\Model;
5
6
abstract class Form extends Model
7
{
8
    /**
9
     * @return self|mixed return model itself if has errors, otherwise returns handled's result.
10
     * @throws \Throwable rethrows exception if no error specified.
11
     */
12 3
    public function handle()
13
    {
14
        try {
15 3
            if (!$this->validate()) {
16
                return $this;
17
            }
18
19
            $data = $this->handleInternal();
20
            return $data;
21 3
        } catch (\Throwable $e) {
22 3
            if ($this->hasErrors()) {
23
                return $this;
24
            }
25
26 3
            throw $e;
27
        }
28
    }
29
    
30
    /**
31
     * @return mixed
32
     */
33
    abstract protected function handleInternal();
34
}