Completed
Push — master ( 591640...0150df )
by Chin
01:03
created

BooleanOptionalModifierProvider::optional()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace ChinLeung\LaravelFakerProviders;
4
5
use Faker\DefaultGenerator;
6
use Faker\Provider\Base;
7
8
class BooleanOptionalModifierProvider extends Base
9
{
10
    /**
11
     * Chainable method for making any formatter optional.
12
     *
13
     * @param  mixed  $weight
14
     * @param  mixed|null  $default
15
     * @return mixed|null
16
     */
17
    public function optional($weight = 0.5, $default = null)
18
    {
19
        if (! is_numeric($weight)) {
20
            return $weight ? $this->generator : new DefaultGenerator($default);
21
        }
22
23
        return parent::optional($weight, $default);
24
    }
25
}
26