Compiler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 5
Bugs 2 Features 1
Metric Value
wmc 4
c 5
b 2
f 1
lcom 0
cbo 1
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B compile() 0 24 4
1
<?php
2
3
namespace Hshn\AngularBundle\TemplateCache;
4
5
use Symfony\Component\Finder\SplFileInfo;
6
7
class Compiler
8
{
9
    /**
10
     * @param SplFileInfo[] $files
11
     * @param string        $moduleName
12
     * @param bool          $newModule
13
     *
14
     * @return string
15
     */
16
    public function compile(array $files, $moduleName, $newModule = false)
17
    {
18
        $output = "'use strict';\n\n";
19
        $output .= $newModule ? "angular.module('{$moduleName}', [])\n" : "angular.module('{$moduleName}')\n";
20
        $output .= "  .run(['\$templateCache', function (\$templateCache) {\n";
21
22
        /* @var $file SplFileInfo */
23
        foreach ($files as $file) {
24
            $templateId = $file->getRelativePathname();
25
            $output .= "    \$templateCache.put('{$templateId}',\n";
26
27
            $html = array();
28
            foreach (new \SplFileObject($file->getPathname(), 'r') as $line) {
29
                $html[] = '    \'' . str_replace(array("\r", "\n", '\''), array('\r', '\n', '\\\''), $line) . "'";
30
            }
31
32
            $output .= implode(" +\n", $html) . ");\n";
33
        }
34
35
        $output .= "  }])\n";
36
        $output .= ";\n";
37
38
        return $output;
39
    }
40
}
41