Passed
Push — master ( a32fcb...d12ca6 )
by Laurens
01:50
created

ManifestGenerator::generate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\ApplePassbook\Build;
6
7
use LauLamanApps\ApplePassbook\Passbook;
8
9
class ManifestGenerator
10
{
11
    public const FILENAME = 'manifest.json';
12
13 2
    public function generate(Passbook $passbook, string $temporaryDirectory): void
14
    {
15 2
        $manifest = [Compiler::PASS_DATA_FILE => $this->hash(json_encode($passbook->getData()))];
16
17 2
        foreach ($passbook->getImages() as $file) {
18 1
            $manifest[$file->getFilename()] = $this->hash($file->getContents());
19
        }
20
21 2
        file_put_contents($temporaryDirectory . '/' . self::FILENAME, json_encode($manifest));
22 2
    }
23
24 2
    private function hash($data): string
25
    {
26 2
        return sha1($data);
27
    }
28
}
29