Completed
Push — master ( 0d6f9c...3d08a4 )
by Roeland
11s
created

ItemMapper::findByFileId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Copyright (c) 2015 Victor Dubiniuk <[email protected]>
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later.
6
 * See the COPYING-README file.
7
 */
8
9
namespace OCA\Files_Antivirus\Db;
10
11
use OCP\AppFramework\Db\DoesNotExistException;
12
use OCP\AppFramework\Db\Entity;
13
use OCP\AppFramework\Db\Mapper;
14
use OCP\IDBConnection;
15
16
class ItemMapper extends Mapper {
17
	public function __construct(IDBConnection $db) {
18
		parent::__construct($db, 'files_antivirus', Item::class);
19
	}
20
21
	/**
22
	 * Find rule by id
23
	 * @param int $fileid
24
	 * @return Rule
25
	 * @throws DoesNotExistException
26
	 */
27
	public function findByFileId($fileid){
28
		$sql = 'SELECT * FROM ' . $this->getTableName() .' WHERE fileid = ?';
29
		return $this->findEntity($sql, [$fileid]);
30
	}
31
32
	public function delete(Entity $entity) {
33
		if (!($entity instanceof Item)) {
34
			throw new \InvalidArgumentException();
35
		}
36
37
		$qb = $this->db->getQueryBuilder();
38
39
		$qb->delete('files_antivirus')
40
			->where(
41
				$qb->expr()->eq('fileid', $qb->createNamedParameter($entity->getFileid()))
42
			);
43
		$qb->execute();
44
45
		return $entity;
46
	}
47
}
48