Test Failed
Pull Request — master (#11)
by Alexander
05:04
created

NumberBehavior::events()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Horat1us\Yii\Behaviors;
4
5
use yii\base\Behavior;
6
use yii\db\ActiveRecord;
7
8
/**
9
 * Class PhoneBehavior
10
 * @package Horat1us\Yii\Behaviors
11
 */
12
class NumberBehavior extends Behavior
13
{
14
    /** @var string|string[] */
15
    public $attributes = [];
16
17
    /**
18
     * @return array
19
     */
20 1
    public function events()
21
    {
22
        return [
23 1
            ActiveRecord::EVENT_BEFORE_VALIDATE => 'map',
24 1
            ActiveRecord::EVENT_BEFORE_INSERT => 'map',
25 1
            ActiveRecord::EVENT_BEFORE_UPDATE => 'map',
26
        ];
27
    }
28
29
    /**
30
     * @return void
31
     */
32 1
    public function map()
33
    {
34 1
        foreach ((array)$this->attributes as $attribute) {
35 1
            $this->owner->{$attribute} = preg_replace("/\D/", '', $this->owner->{$attribute});
36
        }
37
    }
38
}