Skip to content

Commit

Permalink
Правки по стилю кода
Browse files Browse the repository at this point in the history
  • Loading branch information
fdfkc committed Sep 3, 2023
1 parent 69aa25f commit 4797251
Show file tree
Hide file tree
Showing 32 changed files with 78 additions and 177 deletions.
4 changes: 0 additions & 4 deletions code/public/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use VKorabelnikov\Hw16\MusicStreaming\Infrastructure\Storage\DataMapper\PlaylistMapper;
use VKorabelnikov\Hw16\MusicStreaming\Infrastructure\Config\IniConfig;
use VKorabelnikov\Hw16\MusicStreaming\Infrastructure\Storage\ConnectionManager;

use VKorabelnikov\Hw16\MusicStreaming\Infrastructure\HttpApiController\PlaylistController;
use VKorabelnikov\Hw16\MusicStreaming\Infrastructure\HttpApiController\UserController;
use VKorabelnikov\Hw16\MusicStreaming\Infrastructure\HttpApiController\TrackController;
Expand Down Expand Up @@ -195,6 +194,3 @@
"userLogin" => $user2Login
]
);



1 change: 1 addition & 0 deletions code/public/v1/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

require __DIR__ . "/../../vendor/autoload.php";

use VKorabelnikov\Hw16\MusicStreaming\Infrastructure\Init\HttpApiInit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
interface ConfigInterface
{
public function getAllSettings(): Config;
}
}
2 changes: 1 addition & 1 deletion code/src/MusicStreaming/Application/DTO/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class Config
public ?string $connectionDbName;
public ?string $connectionDbUser;
public ?string $connectionDbPassword;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace VKorabelnikov\Hw16\MusicStreaming\Application\DataTransfer;

use function \VKorabelnikov\Hw16\MusicStreaming\Domain\Model\Functions\convertFromIntToString;
use function VKorabelnikov\Hw16\MusicStreaming\Domain\Model\Functions\convertFromIntToString;

class EntityListResponse extends Response
{
Expand All @@ -31,7 +31,7 @@ public function getEntitiesList(): array
private function computeDuration(array $entitiesList): string
{
$totalDuration = 0;
foreach($entitiesList as $entity) {
foreach ($entitiesList as $entity) {
$totalDuration += $entity->getDurationSeconds();
}
return convertFromIntToString($totalDuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class ErrorResponse extends Response
{
protected string $errorDescription;

public function __construct($errorDescription) {
public function __construct($errorDescription)
{
$this->success = false;
$this->errorDescription = $errorDescription;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace VKorabelnikov\Hw16\MusicStreaming\Application\Exceptions;


class TableRowNotFoundException extends \Exception
{

Check failure on line 8 in code/src/MusicStreaming/Application/Exceptions/TableRowNotFoundException.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening brace must not be followed by a blank line

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public function findByGenre(Genre $genre, $limit, $offset): array;
public function insert(Track $track): void;
public function update(Track $track): bool;
public function delete(Track $track): bool;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public function __construct(
PlaylistMapperInterface $playlistMapper,
UserMapperInterface $userMapper,
TrackMapperInterface $trackMapper
)
{
) {
$this->playlistMapper = $playlistMapper;
$this->userMapper = $userMapper;
$this->trackMapper = $trackMapper;
Expand All @@ -36,7 +35,7 @@ public function create(array $playlistParams)

if (
empty($playlistParams["tracksList"])
|| !is_array($playlistParams["tracksList"])
|| !is_array($playlistParams["tracksList"])
) {
throw new \Exception("Incorrect tracksList");
}
Expand All @@ -52,7 +51,7 @@ public function create(array $playlistParams)
public function createPaylistObject($playlistParams): Playlist
{
$tracksList = [];
foreach($playlistParams["tracksList"] as $trackId){
foreach ($playlistParams["tracksList"] as $trackId) {
$tracksList[] = $this->trackMapper->findById((int) $trackId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class FindPlaylistUseCase
public function __construct(
PlaylistMapperInterface $playlistMapper,
UserMapperInterface $userMapper
)
{
) {
$this->playlistMapper = $playlistMapper;
$this->userMapper = $userMapper;
}
Expand Down
10 changes: 4 additions & 6 deletions code/src/MusicStreaming/Application/UseCase/FindTrackUseCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use VKorabelnikov\Hw16\MusicStreaming\Domain\Model\TrackWithSocialLinksInDescription;
use VKorabelnikov\Hw16\MusicStreaming\Domain\Model\TrackWithDurationInDescription;


class FindTrackUseCase
{
protected GenreMapperInterface $genreMapper;
Expand All @@ -21,8 +20,7 @@ public function __construct(
GenreMapperInterface $genreMapper,
UserMapperInterface $userMapper,
TrackMapperInterface $trackMapper
)
{
) {
$this->genreMapper = $genreMapper;
$this->userMapper = $userMapper;
$this->trackMapper = $trackMapper;
Expand All @@ -42,7 +40,7 @@ public function bygenre(array $findParams): array
$itemsPerPage,
$itemsPerPage * ($pageNumber - 1)
);
if($setAdditionalDescription === true) {
if ($setAdditionalDescription === true) {
$tracksList = $this->decorateTracksSocial(
$this->decorateTracksDuration($tracksList)
);
Expand All @@ -54,7 +52,7 @@ public function bygenre(array $findParams): array
protected function decorateTracksSocial(array $tracksList): array
{
$decoratedTracks = [];
foreach($tracksList as $track) {
foreach ($tracksList as $track) {
$decoratedTracks[] = new TrackWithSocialLinksInDescription($track);
}

Expand All @@ -64,7 +62,7 @@ protected function decorateTracksSocial(array $tracksList): array
protected function decorateTracksDuration(array $tracksList): array
{
$decoratedTracks = [];
foreach($tracksList as $track) {
foreach ($tracksList as $track) {
$decoratedTracks[] = new TrackWithDurationInDescription($track);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class UserAuthUseCase

public function __construct(
UserMapperInterface $userMapper
)
{
) {
$this->userMapper = $userMapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class UserRegisterUseCase

public function __construct(
UserMapperInterface $userMapper
)
{
) {
$this->userMapper = $userMapper;
}

Expand Down
4 changes: 2 additions & 2 deletions code/src/MusicStreaming/Domain/Model/Functions/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

function convertFromStringToInt(string $duration): int
{
return empty($duration)? 0: strtotime($duration);
return empty($duration) ? 0 : strtotime($duration);
}

function convertFromIntToString(int $duration): string
{
return date("H:i:s", $duration);
}
}
7 changes: 3 additions & 4 deletions code/src/MusicStreaming/Domain/Model/Genre.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ class Genre
{
const FAKE_ID = -1;

private int $id; // positive int
private string $name; // not empty string
private int $id;
private string $name;

public function __construct(
int $id,
string $name
)
{
) {
$this->id = $id;
$this->name = $name;
}
Expand Down
30 changes: 7 additions & 23 deletions code/src/MusicStreaming/Domain/Model/Playlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace VKorabelnikov\Hw16\MusicStreaming\Domain\Model;

use function \VKorabelnikov\Hw16\MusicStreaming\Domain\Model\Functions\convertFromIntToString;
use function VKorabelnikov\Hw16\MusicStreaming\Domain\Model\Functions\convertFromIntToString;

class Playlist implements \JsonSerializable, DurationInterface
{
const FAKE_ID = -1;

private int $id; // positive int
private string $name; // not empty string
private int $id;
private string $name;
private User $user;
private array $tracksList;

Expand All @@ -20,8 +20,7 @@ public function __construct(
string $name,
User $user,
array $tracksList
)
{
) {
$this->id = $id;
$this->name = $name;
$this->user = $user;
Expand All @@ -31,7 +30,7 @@ public function __construct(
public function jsonSerialize(): mixed
{
return [
"id" => $this->id, /////////////////////////
"id" => $this->id,
"name" => $this->name,
"user" => $this->user->getLogin(),
"tracksList" => $this->tracksList
Expand All @@ -45,7 +44,7 @@ public function getDuration(): string
public function getDurationSeconds(): int
{
$totalDuration = 0;
foreach($this->tracksList as $track) {
foreach ($this->tracksList as $track) {
$totalDuration += $track->getDurationSeconds();
}
return $totalDuration;
Expand Down Expand Up @@ -94,19 +93,4 @@ public function setTracksList(array $tracksList): self
$this->tracksList = $tracksList;
return $this;
}



///////////////// ???????????????????????????

public function addTracksToList(array $tracks): self
{
return $this;
}

public function deleteTracksFromList(): self
{
return $this;
}
}
}
23 changes: 10 additions & 13 deletions code/src/MusicStreaming/Domain/Model/Track.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace VKorabelnikov\Hw16\MusicStreaming\Domain\Model;

use function \VKorabelnikov\Hw16\MusicStreaming\Domain\Model\Functions\convertFromStringToInt;
use function VKorabelnikov\Hw16\MusicStreaming\Domain\Model\Functions\convertFromStringToInt;

class Track implements \JsonSerializable, DurationInterface, TrackInterface
{
const FAKE_ID = -1;


private int $id; // positive int
private string $name; // not empty string
private string $author; // not empty string
private int $id;
private string $name;
private string $author;
private Genre $genre;
private string $duration; // timestamp?
private string $description; // any string
private string $duration;
private string $description;
private string $fileLink;
private User $user;

Expand All @@ -29,8 +29,7 @@ public function __construct(
string $description,
string $fileLink,
User $user
)
{
) {
$this->id = $id;
$this->name = $name;
$this->author = $author;
Expand Down Expand Up @@ -152,12 +151,10 @@ protected function linkToDownload(): string
{
$filePathParts = explode("/", $this->fileLink);
$partsCount = count($filePathParts);
if($partsCount >= 2) {
if ($partsCount >= 2) {
return "/" . $filePathParts[$partsCount - 2] . "/" . $filePathParts[$partsCount - 1];
}
else
{
} else {
return "";
}
}
}
}
11 changes: 1 addition & 10 deletions code/src/MusicStreaming/Domain/Model/TrackDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace VKorabelnikov\Hw16\MusicStreaming\Domain\Model;

class TrackDecorator implements TrackInterface, \JsonSerializable
abstract class TrackDecorator implements TrackInterface, \JsonSerializable
{
protected TrackInterface $track;

Expand Down Expand Up @@ -82,14 +82,5 @@ public function jsonSerialize(): mixed
$trackSerializeArray = $this->track->jsonSerialize();
$trackSerializeArray["description"] = $this->getDescription();
return $trackSerializeArray;
// return [
// "name" => $this->track->getName(),
// "author" => "",
// "genre" => $this->track->getGenre()->getName(),
// "duration" => $this->track->getDuration(),
// "description" => $this->getDescription(),
// "fileLink" => $this->fileLink,
// "user" => $this->user->getLogin()
// ];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function getDescription(): string
{
$description = $this->track->getDescription();
$description .= "<br><br> Duration: "
. (empty($this->track->getDuration())? "unknown": $this->track->getDuration());
. (empty($this->track->getDuration()) ? "unknown" : $this->track->getDuration());
return $description;
}
}
7 changes: 3 additions & 4 deletions code/src/MusicStreaming/Domain/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ class User
const FAKE_ID = -1;


private int $id; // positive int
private string $login; // not empty string
private int $id;
private string $login;
private string $passwordSha1;

public function __construct(
int $id,
string $login,
string $passwordSha1
)
{
) {
$this->id = $id;
$this->login = $login;
$this->passwordSha1 = $passwordSha1;
Expand Down
Empty file.
Loading

0 comments on commit 4797251

Please sign in to comment.