FizzBuzz::generate()   A
last analyzed

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
     * @param  int  $start
11
     * @param  int  $end
12
     * @param  int  $fizz
13
     * @param  int  $buzz
14
     * @return void
15
     */
16 1
    public function __construct(
17
        protected int $start,
18
        protected int $end,
19
        protected int $fizz,
20
        protected int $buzz
21
    ) {
22
        //
23 1
    }
24
25
    /**
26
     * Create a new instance class in a static way.
27
     *
28
     * @param  int  $start
29
     * @param  int  $end
30
     * @param  int  $fizz
31
     * @param  int  $buzz
32
     * @return static
33
     */
34 1
    public static function make(int $start, int $end, int $fizz = 3, int $buzz = 5)
35
    {
36 1
        return new static($start, $end, $fizz, $buzz);
37
    }
38
39
    /**
40
     * Generate list of fizz buzz data.
41
     *
42
     * @return int[]|string[]
43
     */
44 1
    public function generate(): array
45
    {
46 1
        return array_map(function ($number) {
47
            switch (true) {
48 1
                case $number % $this->fizz === 0 && $number % $this->buzz === 0:
49 1
                    return 'Fizz Buzz';
50
51 1
                case $number % $this->fizz === 0:
52 1
                    return 'Fizz';
53
54 1
                case $number % $this->buzz === 0:
55 1
                    return 'Buzz';
56
57
                default:
58 1
                    return $number;
59
            }
60 1
        }, range($this->start, $this->end, 1));
61
    }
62
}
63