Completed
Pull Request — master (#490)
by
unknown
01:54
created

FilePropertiesService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getModifications() 0 8 2
A setModifications() 0 12 2
1
<?php
2
namespace OCA\Gallery\Service;
3
4
use OCA\Gallery\Db\FileProperties;
5
use OCA\Gallery\Db\FilePropertiesMapper;
6
use OCP\AppFramework\Db\DoesNotExistException;
7
use OCA\Gallery\Environment\Environment;
8
use OCP\ILogger;
9
10
class FilePropertiesService extends Service {
11
12
	public function __construct(
13
		$appName,
14
		Environment $environment,
15
		ILogger $logger,
16
		FilePropertiesMapper $mapper
17
	) {
18
		parent::__construct($appName, $environment, $logger);
19
		$this->mapper = $mapper;
0 ignored issues
show
Bug introduced by
The property mapper does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20
	}
21
22
	public function getModifications($fileId) {
23
		try {
24
			$entity = $this->mapper->find($fileId);
25
			return $entity->getModifications();
26
		} catch (DoesNotExistException $ex) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
27
			return "{}";
28
		}
29
	}
30
31
	public function setModifications($fileId, $modificationsJson) {
32
		try {
33
			$entity = $this->mapper->find($fileId);
34
			$entity->setModifications($modificationsJson);
35
			$this->mapper->update($entity);
36
		} catch (DoesNotExistException $ex) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\Db\DoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
37
			$entity = new FileProperties();
38
			$entity->setId($fileId);
39
			$entity->setModifications($modificationsJson);
40
			$this->mapper->insert($entity);
41
		}
42
	}
43
}
44