PackageManifester::createManifest()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
namespace JWage\APNS\Safari;
4
5
class PackageManifester
6
{
7
    /**
8
     * Generates a manifest JSON file and returns the path.
9
     *
10
     * @param \JWage\APNS\Safari\Package $package
11
     * @return string $manifestJsonPath
12
     */
13
    public function createManifest(Package $package)
14
    {
15
        $manifestData = array();
16
        foreach (Package::$packageFiles as $rawFile) {
17
            $filePath = sprintf('%s/%s', $package->getPackageDir(), $rawFile);
18
            $manifestData[$rawFile] = sha1(file_get_contents($filePath));
19
        }
20
21
        $manifestJsonPath = sprintf('%s/manifest.json', $package->getPackageDir());
22
        $manifestJson = json_encode((object) $manifestData);
23
24
        file_put_contents($manifestJsonPath, $manifestJson);
25
26
        return $manifestJsonPath;
27
    }
28
}
29