FileWriter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A write() 0 13 3
1
<?php
2
/**
3
 * This file is part of sitemap-common.
4
 *
5
 * (c) 2016 Daniele Moraschi
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace SiteMap\Output\File;
12
13
use SiteMap\Output\Writer;
14
15
class FileWriter implements Writer
16
{
17
18
    /**
19
     * @var string
20
     */
21
    private $fileName;
22
23
    /**
24
     * FileWriter constructor.
25
     * @param $fileName
26
     */
27
    public function __construct($fileName)
28
    {
29
        $this->fileName = (string)$fileName;
30
    }
31
32
    /**
33
     * @param $fileContent
34
     * @return mixed
35
     */
36
    public function write($fileContent)
37
    {
38
        try {
39
            $success = file_put_contents($this->fileName, $fileContent);
40
            if (false === $success) {
41
                throw new \Exception();
42
            }
43
        } catch (\Exception $e) {
44
            throw new FileWriterException(sprintf('Cannot write the file at location %s', $this->fileName));
45
        }
46
47
        return true;
48
    }
49
}