Completed
Pull Request — master (#1523)
by
unknown
08:52
created

AliasMapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * ownCloud - Mail
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Tahaa Karim <[email protected]>
10
 * @copyright Tahaa Karim 2016
11
 */
12
13
namespace OCA\Mail\Db;
14
15
use OCP\AppFramework\Db\Mapper;
16
use OCP\IDb;
17
use PhpParser\Node\Stmt\TraitUseAdaptation\Alias;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, OCA\Mail\Db\Alias.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
18
19
class AliasMapper extends Mapper {
20
21
	/**
22
	 * @param IDb $db
23
	 */
24
	public function __construct(IDb $db) {
25
		parent::__construct($db, 'mail_aliases');
26
	}
27
28
	/*
29
	 *  TODO: Add function for CRUD by user id and email
30
	 */
31
32
	/**
33
	 * Saves an Alias into the database
34
	 * @param Alias $alias
35
	 * @return Alias
36
	 */
37
	public function save(Alias $alias) {
38
		if (is_null($alias->getId())) {
39
			return $this->insert($alias);
40
		} else {
41
			$this->update($alias);
42
			return $alias;
43
		}
44
	}
45
46
}
47