Passed
Branch main (339f6d)
by Cornelia
17:44 queued 07:47
created

CardFactory::createCard()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace App\Card;
4
5
/**
6
 * Class CardFactory.
7
 *
8
 * Factory class for creating Card or CardGraphic objects,
9
 * depending on configuration.
10
 */
11
class CardFactory
12
{
13
    /**
14
     * Whether to create graphic cards or plain text cards.
15
     */
16
    private bool $useGraphics;
17
18
    /**
19
     * CardFactory constructor.
20
     *
21
     * @param bool $useGraphics true to return CardGraphic instances, false for Card
22
     */
23 32
    public function __construct(bool $useGraphics = false)
24
    {
25 32
        $this->useGraphics = $useGraphics;
26
    }
27
28
    /**
29
     * Creates a card instance based on the factory's setting.
30
     *
31
     * @param string $suit  The suit of the card (e.g. Hearts).
32
     * @param string $value The value of the card (e.g. 10, Queen).
33
     *
34
     * @return Card|CardGraphic a new instance of Card or CardGraphic
35
     */
36
    public function createCard(string $suit, string $value)
37
    {
38
        if ($this->useGraphics) {
39
            return new CardGraphic($suit, $value);
40
        }
41
42
        return new Card($suit, $value);
43
    }
44
}
45