Passed
Push — develop ( bf9913...29023c )
by Septianata
01:50 queued 14s
created

FizzBuzz::generate()   A

Complexity

Conditions 5
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
ccs 10
cts 10
cp 1
crap 5
rs 9.6111
1
<?php
2
3
namespace Ianriizky\CodingInterview\FizzBuzz;
4
5
class FizzBuzz
6
{
7
    /**
8
     * Create a new instance class.
9
     *
10
     * @return void
11
     */
12 1
    public function __construct(
13
        protected int $start,
14
        protected int $end,
15
        protected int $fizz,
16
        protected int $buzz
17
    ) {
18
        //
19 1
    }
20
21
    /**
22
     * Create a new instance class in a static way.
23
     *
24
     * @return static
25
     */
26 1
    public static function make(int $start, int $end, int $fizz = 3, int $buzz = 5)
27
    {
28 1
        return new static($start, $end, $fizz, $buzz);
29
    }
30
31
    /**
32
     * Generate list of fizz buzz data.
33
     *
34
     * @return int[]|string[]
35
     */
36 1
    public function generate(): array
37
    {
38 1
        return array_map(function ($number) {
39
            switch (true) {
40 1
                case $number % $this->fizz === 0 && $number % $this->buzz === 0:
41 1
                    return 'Fizz Buzz';
42
43 1
                case $number % $this->fizz === 0:
44 1
                    return 'Fizz';
45
46 1
                case $number % $this->buzz === 0:
47 1
                    return 'Buzz';
48
49
                default:
50 1
                    return $number;
51
            }
52 1
        }, range($this->start, $this->end, 1));
53
    }
54
}
55