Completed
Pull Request — master (#49)
by Matias
02:08
created

PersonController::updateNameV2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
namespace OCA\FaceRecognition\Controller;
3
4
use OCP\IRequest;
5
use OCP\Files\IRootFolder;
6
use OCP\AppFramework\Http;
7
use OCP\AppFramework\Http\DataResponse;
8
use OCP\AppFramework\Http\JSONResponse;
9
use OCP\AppFramework\Http\DataDisplayResponse;
10
use OCP\AppFramework\Controller;
11
12
use OCA\FaceRecognition\Db\Face;
13
use OCA\FaceRecognition\Db\FaceMapper;
14
15
use OCA\FaceRecognition\Db\Person;
16
use OCA\FaceRecognition\Db\PersonMapper;
17
18
class PersonController extends Controller {
19
20
	private $rootFolder;
21
	private $faceMapper;
22
	private $personMapper;
23
	private $userId;
24
25 View Code Duplication
	public function __construct($AppName, IRequest $request, IRootFolder $rootFolder, FaceMapper $facemapper, PersonMapper $personmapper, $UserId) {
1 ignored issue
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...
26
		parent::__construct($AppName, $request);
27
		$this->rootFolder = $rootFolder;
28
		$this->faceMapper = $facemapper;
29
		$this->personMapper = $personmapper;
30
		$this->userId = $UserId;
31
	}
32
33
	/**
34
	 * @NoAdminRequired
35
	 */
36
	public function index() {
37
		$resp = array();
38
		$groups = $this->faceMapper->getGroups($this->userId);
39
		foreach ($groups as $group) {
40
			$resp[$group->getName()] = $this->faceMapper->findAllNamed($this->userId, $group->getName(), 12);
41
		}
42
		return new DataResponse($resp);
43
	}
44
45
	/**
46
	 * @NoAdminRequired
47
	 *
48
	 * @param string $name
49
	 */
50
	public function getFaces($name) {
51
		$faces = $this->faceMapper->findAllNamed($this->userId, $name);
52
		return new DataResponse($faces);
53
	}
54
55
	/**
56
	 * @NoAdminRequired
57
	 *
58
	 * @param string $oldName
0 ignored issues
show
Bug introduced by
There is no parameter named $oldName. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
59
	 * @param string $newName
60
	 */
61
	public function updateName($name, $newName) {
62
		$faces = $this->faceMapper->findAllNamed($this->userId, $name);
63
		foreach ($faces as $face) {
64
			$face->setName($newName);
65
			$this->faceMapper->update($face);
66
		}
67
		$newFaces = $this->faceMapper->findAllNamed($this->userId, $newName);
68
		return new DataResponse($newFaces);
69
	}
70
71
	/**
72
	 * @NoAdminRequired
73
	 *
74
	 * @param int $id
75
	 * @param string $name
76
	 */
77
	public function updateNameV2($id, $name) {
78
		$person = $this->personMapper->find ($this->userId, $id);
79
		$person->setName($name);
80
		$this->personMapper->update($person);
81
		$newPerson = $this->personMapper->find($this->userId, $id);
82
		return new DataResponse($newPerson);
83
	}
84
85
}
86