Passed
Push — dougall-pheobe-database-map-fi... ( ...2d7731 )
by
unknown
22:10
created

File   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 39
rs 10
c 0
b 0
f 0
ccs 0
cts 9
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createFile() 0 4 1
A maxUploadSize() 0 5 1
A maxUploadSizeString() 0 3 1
1
<?php
2
/**
3
 * @link http://www.newicon.net/neon
4
 * @copyright Copyright (c) 2008 Newicon Ltd
5
 * @license http://www.newicon.net/neon/license/
6
 */
7
8
namespace neon\core\helpers;
9
10
use \neon\core\helpers\Str;
11
12
/**
13
 * Class FileHelper
14
 * @author Steve O'Brien - Newicon Ltd
15
 * @package neon\core\helpers
16
 */
17
class File extends \yii\helpers\FileHelper
18
{
19
	/**
20
	 * Return the number in bytes representing the max upload size.
21
	 * Considers both the PHP post max size and the PHP upload max size.
22
	 * Requires the ini_get function
23
	 *
24
	 * @return int
25
	 */
26
	public static function maxUploadSize()
27
	{
28
		$postMax =  Str::toBytes(ini_get('post_max_size'));
29
		$uploadMax = Str::toBytes(ini_get('upload_max_filesize'));
30
		return min($postMax, $uploadMax);
31
	}
32
33
	/**
34
	 * Return a nicely formatted string representing the max upload size
35
	 *
36
	 * @return string
37
	 */
38
	public static function maxUploadSizeString()
39
	{
40
		return Str::formatBytes(self::maxUploadSize());
41
	}
42
43
	/**
44
	 * Create a file at a give path or alias path
45
	 * This function is similar to file_put_contents however it will ensure the nested directory path exists
46
	 *
47
	 * @param string $path
48
	 * @param string $content
49
	 * @throws \yii\base\Exception if the directory could not be created (i.e. php error due to parallel changes)
50
	 * @return bool|int - the number of bytes written to the file, or false on failure
51
	 */
52
	public static function createFile($path, $content)
53
	{
54
		static::createDirectory(dirname($path));
55
		return file_put_contents($path, $content);
56
	}
57
}