Issues (22)

src/IO/File.php (2 issues)

1
<?php
2
/**
3
 * @category Library
4
 * @license MIT http://opensource.org/licenses/MIT
5
 * @link https://github.com/emlynwest/changelog
6
 */
7
8
namespace ChangeLog\IO;
9
10
use ChangeLog\AbstractIO;
11
use InvalidArgumentException;
12
13
/**
14
 * Allows change logs to be loaded from the file system.
15
 *
16
 * Config can contain the keys 'file' and 'line_separator'. 'file' is not optional.
17
 */
18
class File extends AbstractIO
19
{
20
21
	protected $configDefaults = [
22
		'line_separator' => "\n",
23
	];
24
25
	/**
26
	 * {@inheritdoc}
27
	 *
28
	 * @throws InvalidArgumentException
29
	 */
30 11
	public function getContent()
31
	{
32 11
		$file = $this->getFileLocation();
33
34 10
		$content = file_get_contents($file);
35
36 10
		return explode(
37 10
			$this->getConfig('line_separator'),
0 ignored issues
show
It seems like $this->getConfig('line_separator') can also be of type array; however, parameter $separator of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
			/** @scrutinizer ignore-type */ $this->getConfig('line_separator'),
Loading history...
38 10
			$content
39 10
		);
40
	}
41
42
	/**
43
	 * {@inheritdoc}
44
	 */
45 8
	public function setContent($content)
46
	{
47 8
		$file = $this->getFileLocation();
48 8
		file_put_contents($file, $content);
49
	}
50
51
	/**
52
	 * Gets the file location from the config.
53
	 *
54
	 * @return string
55
	 */
56 12
	protected function getFileLocation()
57
	{
58 12
		$file = $this->getConfig('file');
59
60 12
		if ( ! $file)
61
		{
62 1
			throw new InvalidArgumentException('File not specified.');
63
		}
64
65 11
		return $file;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $file also could return the type array which is incompatible with the documented return type string.
Loading history...
66
	}
67
68
}
69