PageWriter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B write() 6 25 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}