Issues (9)

lib/FileStorage/Adapter/PHPAdapter.php (1 issue)

1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ICanBoogie\Storage\FileStorage\Adapter;
13
14
use ICanBoogie\Storage\FileStorage\Adapter;
15
16
/**
17
 * Data is encoded with `var_export()` and read with `require`.
18
 */
19
class PHPAdapter implements Adapter
20
{
21
	/**
22
	 * @inheritdoc
23
	 */
24
	public function write(string $filename, $data): bool
25
	{
26
		$code = var_export($data, true);
27
		$data = <<<EOT
28
<?php return $code;
29
EOT;
30
31
		return file_put_contents($filename, $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return file_put_contents($filename, $data) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
32
	}
33
34
	/**
35
	 * @inheritdoc
36
	 */
37
	public function read(string $filename)
38
	{
39
		return require $filename;
40
	}
41
}
42