The class ModelFactory has 21 public methods. Consider refactoring ModelFactory to keep number of public methods under 10. Open
final class ModelFactory implements ModelFactoryInterface
{
public function createPlaylist(
int $id
): Playlist {
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
ModelFactory
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
final class ModelFactory implements ModelFactoryInterface
{
public function createPlaylist(
int $id
): Playlist {
Class "ModelFactory" has 21 methods, which is greater than 20 authorized. Split it into smaller classes. Open
final class ModelFactory implements ModelFactoryInterface
- Read upRead up
- Exclude checks
A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.
The class ModelFactory has a coupling between objects value of 22. Consider to reduce the number of dependencies under 13. Open
final class ModelFactory implements ModelFactoryInterface
{
public function createPlaylist(
int $id
): Playlist {
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Return type of createAlbumDisk()
is undeclared type \Ampache\Repository\Model\AlbumDisk
Open
public function createAlbumDisk(
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Song
Open
return new Song(
- Exclude checks
Return type of createTvShow()
is undeclared type \Ampache\Repository\Model\TvShow
Open
public function createTvShow(
- Exclude checks
Return type of createTmpPlaylist()
is undeclared type \Ampache\Repository\Model\Tmp_Playlist
Open
public function createTmpPlaylist(
- Exclude checks
Return type of createRating()
is undeclared type \Ampache\Repository\Model\Rating
Open
public function createRating(
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Democratic
Open
return new Democratic($democraticId);
- Exclude checks
Return type of createUser()
is undeclared type \Ampache\Repository\Model\User
Open
public function createUser(
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Wanted
Open
return new Wanted((int) $wantedId);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Broadcast
Open
return new Broadcast($broadcastId);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Album
Open
return new Album((int) $albumId);
- Exclude checks
Return type of createPodcast()
is undeclared type \Ampache\Repository\Model\Podcast
Open
public function createPodcast(
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\PrivateMsg
Open
return new PrivateMsg($privateMessageId);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\AlbumDisk
Open
return new AlbumDisk((int) $albumDiskId);
- Exclude checks
Return type of createArtist()
is undeclared type \Ampache\Repository\Model\Artist
Open
public function createArtist(
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Video
Open
return new Video($videoId);
- Exclude checks
Return type of createBroadcast()
is undeclared type \Ampache\Repository\Model\Broadcast
Open
public function createBroadcast(
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\User
Open
return new User((int) $userId);
- Exclude checks
Return type of createSearch()
is undeclared type \Ampache\Repository\Model\Search
Open
public function createSearch(
- Exclude checks
Return type of createSong()
is undeclared type \Ampache\Repository\Model\Song
Open
public function createSong(
- Exclude checks
Returning type \Ampache\Repository\Model\PrivateMsg
but createPrivateMsg()
is declared to return \Ampache\Repository\Model\PrivateMessageInterface
Open
return new PrivateMsg($privateMessageId);
- Exclude checks
Parameter $user
has undeclared type ?\Ampache\Repository\Model\User
Open
public function createSearch(
- Exclude checks
Return type of createWanted()
is undeclared type \Ampache\Repository\Model\Wanted
Open
public function createWanted(
- Exclude checks
Return type of createLiveStream()
is undeclared type \Ampache\Repository\Model\Live_Stream
Open
public function createLiveStream(
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Live_Stream
Open
return new Live_Stream($liveStreamId);
- Exclude checks
Return type of createPodcastEpisode()
is undeclared type \Ampache\Repository\Model\Podcast_Episode
Open
public function createPodcastEpisode(
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Tmp_Playlist
Open
return new Tmp_Playlist($tmpPlaylistId);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Search
Open
return new Search((int) $searchId, $searchType, $user);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Rating
Open
return new Rating(
- Exclude checks
Return type of createAlbum()
is undeclared type \Ampache\Repository\Model\Album
Open
public function createAlbum(
- Exclude checks
Return type of createDemocratic()
is undeclared type \Ampache\Repository\Model\Democratic
Open
public function createDemocratic(
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\TvShow
Open
return new TvShow($tvShowId);
- Exclude checks
Return type of createVideo()
is undeclared type \Ampache\Repository\Model\Video
Open
public function createVideo(
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Artist
Open
return new Artist((int) $artistId);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Podcast
Open
return new Podcast($podcastId);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Podcast_Episode
Open
return new Podcast_Episode($podcastEpisodeId);
- Exclude checks
Avoid variables with short names like $id. Configured minimum length is 3. Open
int $id
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The parameter $browse_id is not named in camelCase. Open
public function createBrowse(
?int $browse_id = null,
bool $cached = true
): Browse {
return new Browse(
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}