Completed
Push — master ( d7c3df...71bce5 )
by Daniel
04:08
created
code/MimeUploadValidator.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
 	 * Check if the temporary file has a valid MIME type for it's extension.
27 27
 	 *
28 28
 	 * @uses finfo php extension
29
-	 * @return boolean|null
29
+	 * @return boolean
30 30
 	 */
31 31
 	public function isValidMime() {
32 32
                 $extension = strtolower(pathinfo($this->tmpFile['name'], PATHINFO_EXTENSION));
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@
 block discarded – undo
29 29
 	 * @return boolean|null
30 30
 	 */
31 31
 	public function isValidMime() {
32
-                $extension = strtolower(pathinfo($this->tmpFile['name'], PATHINFO_EXTENSION));
32
+				$extension = strtolower(pathinfo($this->tmpFile['name'], PATHINFO_EXTENSION));
33 33
 
34
-                // we can't check filenames without an extension or no temp file path, let them pass validation.
35
-                if(!$extension || !$this->tmpFile['tmp_name']) return true;
34
+				// we can't check filenames without an extension or no temp file path, let them pass validation.
35
+				if(!$extension || !$this->tmpFile['tmp_name']) return true;
36 36
 
37 37
 		$expectedMimes = $this->getExpectedMimeTypes($this->tmpFile);
38 38
 		if(empty($expectedMimes)) {
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
                 $extension = strtolower(pathinfo($this->tmpFile['name'], PATHINFO_EXTENSION));
33 33
 
34 34
                 // we can't check filenames without an extension or no temp file path, let them pass validation.
35
-                if(!$extension || !$this->tmpFile['tmp_name']) return true;
35
+                if (!$extension || !$this->tmpFile['tmp_name']) return true;
36 36
 
37 37
 		$expectedMimes = $this->getExpectedMimeTypes($this->tmpFile);
38
-		if(empty($expectedMimes)) {
38
+		if (empty($expectedMimes)) {
39 39
 			throw new MimeUploadValidator_Exception(
40 40
 				sprintf('Could not find a MIME type for extension %s', $extension)
41 41
 			);
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
 
44 44
 		$finfo = new finfo(FILEINFO_MIME_TYPE);
45 45
 		$foundMime = $finfo->file($this->tmpFile['tmp_name']);
46
-		if(!$foundMime) {
46
+		if (!$foundMime) {
47 47
 			throw new MimeUploadValidator_Exception(
48 48
 				sprintf('Could not find a MIME type for file %s', $this->tmpFile['tmp_name'])
49 49
 			);
50 50
 		}
51 51
 
52
-		foreach($expectedMimes as $expected) {
53
-			if($this->compareMime($foundMime, $expected)) return true;
52
+		foreach ($expectedMimes as $expected) {
53
+			if ($this->compareMime($foundMime, $expected)) return true;
54 54
 		}
55 55
 		return false;
56 56
 	}
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$extension = strtolower(pathinfo($tmpFile['name'], PATHINFO_EXTENSION));
65 65
 
66 66
 		// if the finfo php extension isn't loaded, we can't complete this check.
67
-		if(!class_exists('finfo')) {
67
+		if (!class_exists('finfo')) {
68 68
 			throw new MimeUploadValidator_Exception('PHP extension finfo is not loaded');
69 69
 		}
70 70
 
@@ -73,14 +73,14 @@  discard block
 block discarded – undo
73 73
 
74 74
 		// Get the mime types set in framework core
75 75
 		$knownMimes = Config::inst()->get('HTTP', 'MimeTypes');
76
-		if(isset($knownMimes[$extension])) {
76
+		if (isset($knownMimes[$extension])) {
77 77
 			$expectedMimes[] = $knownMimes[$extension];
78 78
 		}
79 79
 
80 80
 		// Get the mime types and their variations from mimevalidator
81 81
 		$knownMimes = Config::inst()->get(get_class($this), 'MimeTypes');
82
-		if(isset($knownMimes[$extension])) {
83
-			if(is_array($knownMimes[$extension])) {
82
+		if (isset($knownMimes[$extension])) {
83
+			if (is_array($knownMimes[$extension])) {
84 84
 				$expectedMimes += $knownMimes[$extension];
85 85
 			} else {
86 86
 				$expectedMimes[] = $knownMimes[$extension];
@@ -109,18 +109,18 @@  discard block
 block discarded – undo
109 109
 	}
110 110
 
111 111
 	public function validate() {
112
-		if(parent::validate() === false) return false;
112
+		if (parent::validate() === false) return false;
113 113
 
114 114
 		try {
115 115
 			$result = $this->isValidMime();
116
-			if($result === false) {
116
+			if ($result === false) {
117 117
 				$this->errors[] = _t(
118 118
 					'File.INVALIDMIME',
119 119
 					'File extension does not match known MIME type'
120 120
 				);
121 121
 				return false;
122 122
 			}
123
-		} catch(MimeUploadValidator_Exception $e) {
123
+		} catch (MimeUploadValidator_Exception $e) {
124 124
 			$this->errors[] = _t(
125 125
 				'File.FAILEDMIMECHECK',
126 126
 				'MIME validation failed: {message}',
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,9 @@  discard block
 block discarded – undo
32 32
                 $extension = strtolower(pathinfo($this->tmpFile['name'], PATHINFO_EXTENSION));
33 33
 
34 34
                 // we can't check filenames without an extension or no temp file path, let them pass validation.
35
-                if(!$extension || !$this->tmpFile['tmp_name']) return true;
35
+                if(!$extension || !$this->tmpFile['tmp_name']) {
36
+                	return true;
37
+                }
36 38
 
37 39
 		$expectedMimes = $this->getExpectedMimeTypes($this->tmpFile);
38 40
 		if(empty($expectedMimes)) {
@@ -50,7 +52,9 @@  discard block
 block discarded – undo
50 52
 		}
51 53
 
52 54
 		foreach($expectedMimes as $expected) {
53
-			if($this->compareMime($foundMime, $expected)) return true;
55
+			if($this->compareMime($foundMime, $expected)) {
56
+				return true;
57
+			}
54 58
 		}
55 59
 		return false;
56 60
 	}
@@ -109,7 +113,9 @@  discard block
 block discarded – undo
109 113
 	}
110 114
 
111 115
 	public function validate() {
112
-		if(parent::validate() === false) return false;
116
+		if(parent::validate() === false) {
117
+			return false;
118
+		}
113 119
 
114 120
 		try {
115 121
 			$result = $this->isValidMime();
Please login to merge, or discard this patch.