PageWriter::write()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 17

Duplication

Lines 6
Ratio 24 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 6
loc 25
rs 8.8571
cc 2
eloc 17
nc 2
nop 1
1
<?php
2
3
namespace Fillet\Writer;
4
5
use Symfony\Component\Yaml\Dumper as YamlDumper;
6
7
/**
8
 * Generates a Page for Sculpin
9
 *
10
 * @package Fillet\Writer
11
 */
12
class PageWriter extends AbstractWriter
13
{
14
    /**
15
     * Write out a set of data into a file
16
     *
17
     * @param array $data Data to use for constructing the page
18
     */
19
    public function write($data)
20
    {
21
        $post_date_string = $data['post_date']->format('Y-m-d H:i:s');
22
        $filename = $this->generateSlug($data['title']);
23
24
        $headerData = [
25
			'title' => $data['title'],
26
			'date' => $post_date_string,
27
			'layout' => 'page',
28
			'slug' => $filename,
29
		];
30
31
		$dumper = new YamlDumper();
32
		$header = '---' . PHP_EOL . $dumper->dump($headerData, 2) . '---' . PHP_EOL;
33
        
34
        $filename = $this->destinationFolder . '/' . $filename;
35 View Code Duplication
        if ($this->isMarkdownEnabled()) {
36
            $filename .= '.md';
37
            $data['content'] = $this->toMarkdown($data['content']);
38
        } else {
39
            $filename .= '.html';
40
        }
41
42
        file_put_contents($filename, $header . PHP_EOL . $data['content']);
43
    }
44
}