| @@ 86-105 (lines=20) @@ | ||
| 83 | * |
|
| 84 | * @return Aperture |
|
| 85 | */ |
|
| 86 | public static function fromFocalLength($focalLength) |
|
| 87 | { |
|
| 88 | if (!is_string($focalLength)) { |
|
| 89 | throw new InvalidArgumentException('focalLength must be a string'); |
|
| 90 | } |
|
| 91 | ||
| 92 | if (!preg_match('#^f/([0-9]*\.[0-9]+|[0-9]*)$#', $focalLength, $matches)) { |
|
| 93 | throw new RuntimeException('Given focalLength is not in a valid format. Need: "f/<number>"'); |
|
| 94 | } |
|
| 95 | ||
| 96 | $fNumber = $matches[1]; |
|
| 97 | ||
| 98 | if (($filtered = filter_var($fNumber, FILTER_VALIDATE_INT)) !== false) { |
|
| 99 | $fNumber = $filtered; |
|
| 100 | } else { |
|
| 101 | $fNumber = (float) $fNumber; |
|
| 102 | } |
|
| 103 | ||
| 104 | return new self($fNumber); |
|
| 105 | } |
|
| 106 | ||
| 107 | /** |
|
| 108 | * Creates a new instance from given Aperture object |
|
| @@ 115-134 (lines=20) @@ | ||
| 112 | * |
|
| 113 | * @return Filesize |
|
| 114 | */ |
|
| 115 | public static function fromMegaBytesString($filesize) |
|
| 116 | { |
|
| 117 | if (!is_string($filesize)) { |
|
| 118 | throw new InvalidArgumentException('Given filesize must be a string'); |
|
| 119 | } |
|
| 120 | ||
| 121 | if (!preg_match('#^([0-9]*\.[0-9]+|[0-9]*)\s?MB$#', $filesize, $matches)) { |
|
| 122 | throw new RuntimeException('Given filesize is not in a valid format. Need: "<float> MB"'); |
|
| 123 | } |
|
| 124 | ||
| 125 | $megabytes = $matches[1]; |
|
| 126 | ||
| 127 | if (($filtered = filter_var($megabytes, FILTER_VALIDATE_INT)) !== false) { |
|
| 128 | $megabytes = $filtered; |
|
| 129 | } else { |
|
| 130 | $megabytes = (float) $megabytes; |
|
| 131 | } |
|
| 132 | ||
| 133 | return self::fromMegaBytes($megabytes); |
|
| 134 | } |
|
| 135 | ||
| 136 | /** |
|
| 137 | * Creates new instance from megabyte amount |
|
| @@ 171-190 (lines=20) @@ | ||
| 168 | * |
|
| 169 | * @return Filesize |
|
| 170 | */ |
|
| 171 | public static function fromKiloBytesString($filesize) |
|
| 172 | { |
|
| 173 | if (!is_string($filesize)) { |
|
| 174 | throw new InvalidArgumentException('Given filesize must be a string'); |
|
| 175 | } |
|
| 176 | ||
| 177 | if (!preg_match('#^([0-9]*\.[0-9]+|[0-9]*)\s?KB$#', $filesize, $matches)) { |
|
| 178 | throw new RuntimeException('Given filesize is not in a valid format. Need: "<float> KB"'); |
|
| 179 | } |
|
| 180 | ||
| 181 | $kilobytes = $matches[1]; |
|
| 182 | ||
| 183 | if (($filtered = filter_var($kilobytes, FILTER_VALIDATE_INT)) !== false) { |
|
| 184 | $kilobytes = $filtered; |
|
| 185 | } else { |
|
| 186 | $kilobytes = (float) $kilobytes; |
|
| 187 | } |
|
| 188 | ||
| 189 | return self::fromKiloBytes($kilobytes); |
|
| 190 | } |
|
| 191 | ||
| 192 | /** |
|
| 193 | * Creates new instance from kilobyte amount |
|