Passed
Push — master ( 9601bc...40dd50 )
by Evgeniy
02:37
created

JsonAssetExporter::export()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Assets\Exporter;
6
7
use JsonException;
8
use RuntimeException;
9
use Yiisoft\Assets\AssetExporterInterface;
10
use Yiisoft\Assets\AssetUtil;
11
use Yiisoft\Json\Json;
12
13
/**
14
 * Exports asset bundles with the values of all properties {@see AssetBundle::jsonSerialize()} to a JSON file.
15
 */
16
final class JsonAssetExporter implements AssetExporterInterface
17
{
18
    /**
19
     * @var string The full path to the target JSON file.
20
     */
21
    private string $targetFile;
22
23
    /**
24
     * @param string $targetFile The full path to the target JSON file.
25
     */
26 5
    public function __construct(string $targetFile)
27
    {
28 5
        $this->targetFile = $targetFile;
29 5
    }
30
31
    /**
32
     * {@inheritDoc}
33
     *
34
     * @throws JsonException If an error occurred during JSON encoding of asset bundles.
35
     * @throws RuntimeException If an error occurred while writing to the JSON file.
36
     */
37 4
    public function export(array $assetBundles): void
38
    {
39 4
        AssetUtil::exportToFile($this->targetFile, Json::encode($assetBundles));
40 3
    }
41
}
42