FileSystem::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6
Metric Value
dl 12
loc 12
ccs 0
cts 11
cp 0
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * ownCloud - Load an image from the virtual file system.
4
 *
5
 * @author Thomas Tanghus
6
 * @copyright 2014 Thomas Tanghus ([email protected])
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OCA\Contacts\Utils\TemporaryPhoto;
24
25
use OCA\Contacts\Contact as ContactObject,
26
	OCA\Contacts\Utils\TemporaryPhoto as BaseTemporaryPhoto,
27
	OCP\AppFramework\Http,
28
	OCP\ICache;
29
30
/**
31
 * This class loads an image from the virtual file system.
32
 */
33
class FileSystem extends BaseTemporaryPhoto {
34
35
	/**
36
	 * The virtual file system path to load the image from
37
	 *
38
	 * @var string
39
	 */
40
	protected $path;
41
42 View Code Duplication
	public function __construct(ICache $cache, $path) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
		\OCP\Util::writeLog('contacts', __METHOD__.' path: ' . $path, \OCP\Util::DEBUG);
44
		if (!is_string($path)) {
45
			throw new \Exception(
46
				__METHOD__ . ' Second argument must a string'
47
			);
48
		}
49
50
		parent::__construct($cache);
51
		$this->path = $path;
52
		$this->processImage();
53
	}
54
55
	/**
56
	 * Load the image.
57
	 */
58
	protected function processImage() {
59
		$localPath = \OC\Files\Filesystem::getLocalFile($this->path);
60
61
		if (!file_exists($localPath)) {
62
			throw new \Exception(
63
				'The file does not exist: ' . $localPath,
64
				Http::STATUS_NOT_FOUND
65
			);
66
		}
67
68
		$this->image = new \OCP\Image();
69
		$this->image->loadFromFile($localPath);
70
	}
71
72
}