Completed
Push — master ( af3ab7...be78bc )
by Patrick
02:17
created

InstrumentBase::getDefaultStopLength()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace ExtendedStrings\Strings\Instrument;
6
7
use ExtendedStrings\Strings\Note;
8
9
abstract class InstrumentBase implements InstrumentInterface
10
{
11
    protected $defaultStopLength;
12
13
    private $stringFrequencies = [];
14
    private $stopLength;
15
16
    /**
17
     * Violin constructor.
18
     *
19
     * @param array|null $stringFrequencies
20
     * @param float      $stopLength
21
     */
22
    public function __construct(array $stringFrequencies = null, float $stopLength = null)
23
    {
24
        if (null === $stringFrequencies) {
25
            $stringFrequencies = array_map(function ($name) {
26
                return Note::fromName($name)->getFrequency();
27
            }, $this->getDefaultNames());
28
        }
29
        if (null === $stopLength) {
30
            $stopLength = $this->getDefaultStopLength();
31
        }
32
33
        $this->stringFrequencies = $stringFrequencies;
34
        $this->stopLength = $stopLength;
35
    }
36
37
    /**
38
     * @return string[] The default strings of the instrument, as note names
39
     *                  (e.g. 'A4', 'D3').
40
     */
41
    abstract protected function getDefaultNames(): array;
42
43
    /**
44
     * @return float The default stop length of the instrument (mm).
45
     */
46
    abstract protected function getDefaultStopLength(): float;
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getStringFrequencies(): array
52
    {
53
        return $this->stringFrequencies;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getStopLength(): float
60
    {
61
        return $this->stopLength;
62
    }
63
}
64