| 1 | <?php |
||
| 4 | class Morsecode |
||
| 5 | { |
||
| 6 | /** |
||
| 7 | * @var array |
||
| 8 | */ |
||
| 9 | private $translation = [ |
||
| 10 | '0' => '-----', |
||
| 11 | '1' => '.----', |
||
| 12 | '2' => '..---', |
||
| 13 | '3' => '...--', |
||
| 14 | '4' => '....-', |
||
| 15 | '5' => '.....', |
||
| 16 | '6' => '-....', |
||
| 17 | '7' => '--...', |
||
| 18 | '8' => '---..', |
||
| 19 | '9' => '----.', |
||
| 20 | 'a' => '.-', |
||
| 21 | 'b' => '-...', |
||
| 22 | 'c' => '-.-.', |
||
| 23 | 'd' => '-..', |
||
| 24 | 'e' => '.', |
||
| 25 | 'f' => '..-.', |
||
| 26 | 'g' => '--.', |
||
| 27 | 'h' => '....', |
||
| 28 | 'i' => '..', |
||
| 29 | 'j' => '.---', |
||
| 30 | 'k' => '-.-', |
||
| 31 | 'l' => '.-..', |
||
| 32 | 'm' => '--', |
||
| 33 | 'n' => '-.', |
||
| 34 | 'o' => '---', |
||
| 35 | 'p' => '.--.', |
||
| 36 | 'q' => '--.-', |
||
| 37 | 'r' => '.-.', |
||
| 38 | 's' => '...', |
||
| 39 | 't' => '-', |
||
| 40 | 'u' => '..-', |
||
| 41 | 'v' => '...-', |
||
| 42 | 'w' => '.--', |
||
| 43 | 'x' => '-..-', |
||
| 44 | 'y' => '-.--', |
||
| 45 | 'z' => '--..', |
||
| 46 | '.' => '.-.-.-', |
||
| 47 | ',' => '--..--', |
||
| 48 | '?' => '..--..', |
||
| 49 | '!' => '-.-.--', |
||
| 50 | '-' => '-....-', |
||
| 51 | '/' => '-..-.', |
||
| 52 | '@' => '.--.-.', |
||
| 53 | '(' => '-.--.', |
||
| 54 | ')' => '-.--.-', |
||
| 55 | ' ' => '/', |
||
| 56 | ]; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * The value the class constructed with. |
||
| 60 | * |
||
| 61 | * @var string |
||
| 62 | */ |
||
| 63 | private $value = ''; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Morsecode constructor. |
||
| 67 | * |
||
| 68 | * @param string $value |
||
| 69 | */ |
||
| 70 | 2 | public function __construct(string $value = '') |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @param string $str |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | 1 | public function encode(string $str = '', string $result = ''): string |
|
| 93 | |||
| 94 | /** |
||
| 95 | * @param string $str |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | 1 | public function decode(string $str = '', string $result = ''): string |
|
| 113 | } |
||
| 114 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.