Completed
Push — master ( 0da1f0...b17898 )
by Patrick
01:56
created

Harmonic::isNatural()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ExtendedStrings\Harmonics;
6
7
class Harmonic
8
{
9
    private $halfStop;
10
    private $baseStop;
11
12
    /**
13
     * @param float $halfStop
14
     * @param float $baseStop
15
     */
16
    public function __construct(float $halfStop, float $baseStop = 1.0)
17
    {
18
        if ($halfStop > $baseStop) {
19
            throw new \InvalidArgumentException("The half-stop's string length cannot be longer than the base stop's.");
20
        }
21
22
        $this->baseStop = $baseStop;
23
        $this->halfStop = $halfStop;
24
    }
25
26
    /**
27
     * @param \ExtendedStrings\Harmonics\VibratingString $string
28
     *
29
     * @return float
30
     */
31
    public function getSoundingPitch(VibratingString $string): float
32
    {
33
        // Transpose the half-stop onto the new string length, which was formed
34
        // by the stop.
35
        $pseudoString = new VibratingString($string->getStoppedFrequency($this->baseStop));
36
        $pseudoHalfStop = $this->halfStop / $this->baseStop;
37
38
        return $pseudoString->getHarmonicSoundingFrequency($pseudoHalfStop);
39
    }
40
}
41