PostWriter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 17.14 %

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 35
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B write() 6 27 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 Post for Sculpin
9
 *
10
 * @package Fillet\Writer
11
 */
12
class PostWriter 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
        $slug = $this->generateSlug($data['title']);
23
        $filename = $data['post_date']->format('Y-m-d') . '-' . $slug;
24
25
		$headerData = [
26
			'title' => $data['title'],
27
			'date' => $post_date_string,
28
			'layout' => 'post',
29
			'slug' => $slug,
30
			'categories' => $data['categories'],
31
			'tags' => $data['tags'],
32
		];
33
34
		$dumper = new YamlDumper();
35
		$header = '---' . PHP_EOL . $dumper->dump($headerData, 2) . '---' . PHP_EOL;
36
37
        $filename = $this->destinationFolder . $filename;
38 View Code Duplication
        if ($this->isMarkdownEnabled()) {
39
            $filename .= '.md';
40
            $data['content'] = $this->toMarkdown($data['content']);
41
        } else {
42
            $filename .= '.html';
43
        }
44
        file_put_contents($filename, $header . PHP_EOL . $data['content']);
45
    }
46
}