JsonLoader   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 2
eloc 6
c 2
b 0
f 2
dl 0
loc 13
rs 10
ccs 4
cts 5
cp 0.8

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseFile() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Translation\Loaders;
5
6
use Nette\Utils\Json;
7
8
/**
9
 * JsonLoader
10
 * Loads texts from json files
11
 *
12
 * @author Jakub Konečný
13
 */
14 1
final class JsonLoader extends FileLoader {
15
  protected $extension = "json";
16
  
17
  /**
18
   * @throws \RuntimeException
19
   * @throws \Nette\Utils\JsonException
20
   */
21
  protected function parseFile(string $filename): array {
22 1
    $content = file_get_contents($filename);
23 1
    if($content === false) {
24
      throw new \RuntimeException("File $filename does not exist or cannot be read.");
25
    }
26 1
    return Json::decode($content, Json::FORCE_ARRAY);
27
  }
28
}
29
?>