SoftIncluder::includeFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL, Commercial license.
5
 *
6
 * @package maslosoft/addendum
7
 * @licence AGPL, Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]> (Meta container, further improvements, bugfixes)
9
 * @copyright Copyright (c) Maslosoft (Meta container, further improvements, bugfixes)
10
 * @copyright Copyright (c) Jan Suchal (Original version, builder, parser)
11
 * @link https://maslosoft.com/addendum/ - maslosoft addendum
12
 * @link https://code.google.com/p/addendum/ - original addendum project
13
 */
14
15
namespace Maslosoft\Addendum\Helpers;
16
17
/**
18
 * This is wrapper for php's built in `include` to include files without warning if file does not exists.
19
 * This will however raise any errors if file is bogus.
20
 *
21
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
22
 */
23
class SoftIncluder
24
{
25
26
	/**
27
	 * Softly include file
28
	 * @param string $filename
29
	 * @return mixed
30
	 */
31 56
	public static function includeFile($filename)
32
	{
33
		// Error reporting here is temporarily changed to ignore warnings.
34
		// This is to avoid include warning.
35 56
		$er = error_reporting(E_ERROR);
36
37
		// Ignore file exists check for better performance, as mostly it should be there
38 56
		$data = include $filename;
39 56
		error_reporting($er);
40 56
		return $data;
41
	}
42
43
}
44