Passed
Push — feature/playlist_improvements ( 2a690a...faf9ee )
by Pauli
14:31
created

Genre::unknownNameString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 6
rs 10
1
<?php
2
3
/**
4
 * ownCloud - Music app
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Pauli Järvinen <[email protected]>
10
 * @copyright Pauli Järvinen 2020
11
 */
12
13
namespace OCA\Music\Db;
14
15
use \OCP\IL10N;
0 ignored issues
show
Bug introduced by
The type OCP\IL10N was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use \OCP\AppFramework\Db\Entity;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Db\Entity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
/**
19
 * @method string getUserId()
20
 * @method void setUserId(string $userId)
21
 * @method string getName()
22
 * @method void setName(string $name)
23
 * @method string getLowerName()
24
 * @method void setLowerName(string $lowerName)
25
 * @method int getTrackCount()
26
 * @method void setTrackCount(int $count)
27
 * @method int getAlbumCount()
28
 * @method void setAlbumCount(int $count)
29
 * @method int getArtistCount()
30
 * @method void setArtistCount(int $count)
31
 * @method array getTrackIds()
32
 * @method void setTrackIds(array $trackIds)
33
 */
34
class Genre extends Entity {
35
	public $userId;
36
	public $name;
37
	public $lowerName;
38
	// not from the music_genres table but still part of the standard content of this entity
39
	public $trackCount;
40
	public $albumCount;
41
	public $artistCount;
42
43
	// not part of the standard content, injected separately when needed
44
	public $trackIds;
45
46
	public function __construct() {
47
		$this->addType('trackCount', 'int');
48
		$this->addType('albumCount', 'int');
49
		$this->addType('artistCount', 'int');
50
	}
51
52
	public function getNameString(IL10N $l10n) {
53
		return $this->getName() ?: self::unknownNameString($l10n);
54
	}
55
56
	public function toApi() {
57
		return  [
58
			'id' => $this->getId(),
59
			'name' => $this->getName(),
60
			'trackIds' => $this->trackIds ? \array_map('\intval', $this->trackIds) : []
61
		];
62
	}
63
64
	public static function unknownNameString(IL10N $l10n) {
65
		$name = $l10n->t('(Unknown genre)');
66
		if (!\is_string($name)) {
67
			/** @var \OC_L10N_String $name */
68
			$name = $name->__toString();
69
		}
70
		return $name;
71
	}
72
}
73