Compare commits

..

No commits in common. "441fdc06b32df8840b0e96efc058eadb9156fb7a" and "5e2f8787ae8db5fedc1a65ca83b93ff91643caca" have entirely different histories.

14 changed files with 398 additions and 180 deletions

View file

@ -1,14 +1,26 @@
<?php
declare(strict_types=1);
namespace App\DTO\Api;
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
/** TODO: Refactor to public readonly */
class Auth implements ValidableInterface
{
private ?string $token;
private ?string $csRfToken;
private ?string $error;
/**
* @var string|null
*/
private $token;
/**
* @var string|null
*/
private $csRfToken;
/**
* @var string|null
*/
private $error;
public function getToken(): ?string
{
@ -42,6 +54,10 @@ class Auth implements ValidableInterface
public function isValid(): bool
{
return null !== $this->token && null !== $this->csRfToken && null === $this->error;
if (null !== $this->token && null !== $this->csRfToken && null === $this->error) {
return true;
}
return false;
}
}
}

View file

@ -1,18 +1,46 @@
<?php
declare(strict_types=1);
namespace App\DTO\Api;
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\User;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
/** TODO: Refactor to public readonly */
class Comment implements ValidableInterface
{
private ?string $postId;
private ?int $number;
private ?int $toCommentId;
private ?string $created;
private ?string $text;
private ?User $author;
private ?bool $isRec;
/**
* @var string|null
*/
private $postId;
/**
* @var int|null
*/
private $number;
/**
* @var int|null
*/
private $toCommentId;
/**
* @var string|null
*/
private $created;
/**
* @var string|null
*/
private $text;
/**
* @var User|null
*/
private $author;
/**
* @var bool|null
*/
private $isRec;
public function getPostId(): ?string
@ -92,6 +120,10 @@ class Comment implements ValidableInterface
public function isValid(): bool
{
return null !== $this->postId && null !== $this->number && null !== $this->author && null !== $this->text;
if (null !== $this->postId && null !== $this->number && null !== $this->author && null !== $this->text) {
return true;
}
return false;
}
}
}

View file

@ -0,0 +1,56 @@
<?php
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\Comment;
use src\PointToolsBundle\DTO\Api\Post;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
class MetaPost implements ValidableInterface
{
/**
* @var Post|null
*/
private $post;
/**
* @var Comment[]|null
*/
private $comments;
public function getPost(): ?Post
{
return $this->post;
}
public function setPost(?Post $post): void
{
$this->post = $post;
}
/**
* @return Comment[]|null
*/
public function getComments(): ?array
{
return $this->comments;
}
/**
* @param Comment[]|null $comments
*/
public function setComments(?array $comments): void
{
$this->comments = $comments;
}
public function isValid(): bool
{
if (null !== $this->post && $this->post->isValid()) {
return true;
}
return false;
}
}

View file

@ -1,21 +1,52 @@
<?php
declare(strict_types=1);
namespace App\DTO\Api;
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\User;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
/** TODO: Refactor to public readonly */
class Post implements ValidableInterface
{
private ?string $id;
/** @var string[]|null */
private ?array $tags;
/** @var string[]|null */
private ?array $files;
private ?User $author;
private ?string $text;
private ?string $created;
private ?string $type;
private ?bool $private;
/**
* @var string|null
*/
private $id;
/**
* @var string[]|null
*/
private $tags;
/**
* @var string[]|null
*/
private $files;
/**
* @var User|null
*/
private $author;
/**
* @var string|null
*/
private $text;
/**
* @var string|null
*/
private $created;
/**
* @var string|null
*/
private $type;
/**
* @var bool|null
*/
private $private;
public function getId(): ?string
{
@ -27,7 +58,9 @@ class Post implements ValidableInterface
$this->id = $id;
}
/** @return string[]|null */
/**
* @return string[]|null
*/
public function getTags(): ?array
{
return $this->tags;
@ -38,7 +71,9 @@ class Post implements ValidableInterface
$this->tags = $tags;
}
/** @return string[]|null */
/**
* @return string[]|null
*/
public function getFiles(): ?array
{
return $this->files;
@ -109,13 +144,18 @@ class Post implements ValidableInterface
public function isValid(): bool
{
return null !== $this->id &&
if (
null !== $this->id &&
null !== $this->author &&
$this->author->isValid() &&
null !== $this->text &&
null !== $this->created
null !== $this->created// &&
// @todo check type existence in incoming data
//null !== $this->type
;
) {
return true;
}
return false;
}
}

View file

@ -1,22 +1,33 @@
<?php
declare(strict_types=1);
namespace App\DTO\Api;
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\MetaPost;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
/** TODO: Refactor to public readonly */
class PostsPage implements ValidableInterface
{
/** @var MetaPost[]|null */
private ?array $posts;
private ?bool $hasNext;
/**
* @var MetaPost[]|null
*/
private $posts;
/** @return MetaPost[]|null */
/**
* @var bool|null
*/
private $hasNext;
/**
* @return MetaPost[]|null
*/
public function getPosts(): ?array
{
return $this->posts;
}
/** @param MetaPost[]|null $posts */
/**
* @param MetaPost[]|null $posts
*/
public function setPosts(?array $posts): void
{
$this->posts = $posts;
@ -34,6 +45,10 @@ class PostsPage implements ValidableInterface
public function isValid(): bool
{
return null !== $this->posts;
if (null !== $this->posts) {
return true;
}
return false;
}
}
}

View file

@ -1,25 +1,81 @@
<?php
declare(strict_types=1);
namespace App\DTO\Api;
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
/** TODO: Refactor to public readonly */
class User implements ValidableInterface
{
private ?string $id;
private ?string $login;
private ?string $name;
private ?string $about;
private ?string $xmpp;
private ?string $created;
private ?bool $gender;
private ?bool $denyAnonymous;
private ?bool $private;
private ?string $birthDate;
private ?string $homepage;
private ?string $email;
private ?string $location;
private ?string $error;
/**
* @var string|null
*/
private $id;
/**
* @var string|null
*/
private $login;
/**
* @var string|null
*/
private $name;
/**
* @var string|null
*/
private $about;
/**
* @var string|null
*/
private $xmpp;
/**
* @var string|null
*/
private $created;
/**
* @var bool|null
*/
private $gender;
/**
* @var bool|null
*/
private $denyAnonymous;
/**
* @var bool|null
*/
private $private;
/**
* @var string|null
*/
private $birthDate;
/**
* @var string|null
*/
private $homepage;
/**
* @var string|null
*/
private $email;
/**
* @var string|null
*/
private $location;
/**
* @var string|null
*/
private $error;
public function getId(): ?string
{
@ -163,6 +219,10 @@ class User implements ValidableInterface
public function isValid(): bool
{
return null === $this->error && null !== $this->id && null !== $this->login;
if (null === $this->error && null !== $this->id && null !== $this->login) {
return true;
}
return false;
}
}
}

View file

@ -1,9 +1,7 @@
<?php
declare(strict_types=1);
namespace App\DTO\Api;
namespace src\PointToolsBundle\DTO\Api;
interface ValidableInterface
{
public function isValid(): bool;
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace src\PointToolsBundle\DTO;
/**
* Events count by day
*/
class DailyEvents
{
/**
* @var \DateTime
*/
private $date;
/**
* @var int
*/
private $eventsCount;
public function __construct(string $date, int $eventsCount)
{
$this->date = new \DateTime($date);
$this->eventsCount = $eventsCount;
}
public function getDate(): \DateTime
{
return $this->date;
}
public function getEventsCount(): int
{
return $this->eventsCount;
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace src\PointToolsBundle\DTO;
/**
* Data Transfer Object for top users list
*/
class TopUserDTO
{
/**
* @var string
*/
private $login;
/**
* @var int
*/
private $subscribersCount;
public function __construct(string $login, int $subscribersCount)
{
$this->login = $login;
$this->subscribersCount = $subscribersCount;
}
public function getLogin(): string
{
return $this->login;
}
public function getSubscribersCount(): int
{
return $this->subscribersCount;
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace src\PointToolsBundle\Service\Factory\Telegram;
use Psr\Log\LoggerInterface;
use src\PointToolsBundle\Entity\Telegram\Account;
use src\PointToolsBundle\Repository\Telegram\AccountRepository;
use src\PointToolsBundle\Service\Factory\AbstractFactory;
use unreal4u\TelegramAPI\Telegram\Types\Message;
class AccountFactory extends AbstractFactory
{
/** @var AccountRepository */
private $accountRepo;
public function __construct(LoggerInterface $logger, AccountRepository $accountRepository)
{
parent::__construct($logger);
$this->accountRepo = $accountRepository;
}
public function findOrCreateFromMessage(Message $message): Account
{
if (null === $account = $this->accountRepo->findOneBy(['id' => $message->from->id])) {
$account = new Account($message->from->id);
$this->accountRepo->add($account);
}
// Setting/updating account data
$account->updateFromMessageData(
$message->from->first_name,
$message->from->last_name,
$message->from->username,
$message->chat->id
);
return $account;
}
}

View file

@ -1,40 +0,0 @@
<?php
declare(strict_types=1);
namespace App\DTO\Api;
/** TODO: Refactor to public readonly */
class MetaPost implements ValidableInterface
{
private ?Post $post;
/** @var Comment[]|null */
private ?array $comments;
public function getPost(): ?Post
{
return $this->post;
}
public function setPost(?Post $post): void
{
$this->post = $post;
}
/** @return Comment[]|null */
public function getComments(): ?array
{
return $this->comments;
}
/** @param Comment[]|null $comments */
public function setComments(?array $comments): void
{
$this->comments = $comments;
}
public function isValid(): bool
{
return null !== $this->post && $this->post->isValid();
}
}

View file

@ -1,17 +0,0 @@
<?php
declare(strict_types=1);
namespace App\DTO;
/** Events count by day */
class DailyEventsDTO
{
public readonly \DateTime $date;
public function __construct(
string $date,
public readonly int $eventsCount,
) {
$this->date = new \DateTime($date);
}
}

View file

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace App\DTO;
/** Data Transfer Object for top users list */
class TopUserDTO
{
public function __construct(
public readonly string $login,
public readonly int $subscribersCount,
) {
}
}

View file

@ -1,38 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Factory\Telegram;
use App\Factory\AbstractFactory;
use Psr\Log\LoggerInterface;
use App\Entity\Telegram\Account;
use App\Repository\Telegram\AccountRepository;
use unreal4u\Telegram\Types\Message;
class AccountFactory extends AbstractFactory
{
public function __construct(
LoggerInterface $logger,
private readonly AccountRepository $accountRepository,
) {
parent::__construct($logger);
}
public function findOrCreateFromMessage(Message $message): Account
{
if (null === $account = $this->accountRepository->findOneBy(['id' => $message->from->id])) {
$account = new Account($message->from->id);
$this->accountRepository->save($account);
}
// Setting/updating account data
$account->updateFromMessageData(
$message->from->first_name,
$message->from->last_name,
$message->from->username,
$message->chat->id
);
return $account;
}
}