Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/fulltextsearch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/Model
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-10-31 20:40:45 +0300
committerMaxence Lange <maxence@artificial-owl.com>2018-10-31 20:40:45 +0300
commit57f01b5e0635291e7334293a929b005c5172af8c (patch)
tree9937ff984dda712ee04f5245f762aac6dcf0dd8e /lib/Model
parentf60c1b1f740bd28efc10d7715184115193e6a9a0 (diff)
migrating php7
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Model')
-rw-r--r--lib/Model/Index.php36
-rw-r--r--lib/Model/IndexOptions.php49
-rw-r--r--lib/Model/PlatformWrapper.php16
-rw-r--r--lib/Model/ProviderIndexes.php15
-rw-r--r--lib/Model/ProviderWrapper.php18
-rw-r--r--lib/Model/Runner.php70
-rw-r--r--lib/Model/SearchRequest.php80
-rw-r--r--lib/Model/SearchResult.php76
-rw-r--r--lib/Model/Tick.php99
9 files changed, 282 insertions, 177 deletions
diff --git a/lib/Model/Index.php b/lib/Model/Index.php
index 34ba9dc..dd25e68 100644
--- a/lib/Model/Index.php
+++ b/lib/Model/Index.php
@@ -30,13 +30,23 @@ declare(strict_types=1);
namespace OCA\FullTextSearch\Model;
+
+use daita\MySmallPhpTools\Traits\TArrayTools;
use JsonSerializable;
use OCP\FullTextSearch\Model\IIndex;
+/**
+ * Class Index
+ *
+ * @package OCA\FullTextSearch\Model
+ */
class Index implements IIndex, JsonSerializable {
+ use TArrayTools;
+
+
/** @var string */
private $providerId;
@@ -229,11 +239,7 @@ class Index implements IIndex, JsonSerializable {
* @return string
*/
public function getOption(string $option, string $default = ''): string {
- if (!array_key_exists($option, $this->options)) {
- return $default;
- }
-
- return $this->options[$option];
+ return $this->get($option, $this->options, $default);
}
@@ -244,13 +250,10 @@ class Index implements IIndex, JsonSerializable {
* @return int
*/
public function getOptionInt(string $option, int $default = 0): int {
- if (!array_key_exists($option, $this->options)) {
- return $default;
- }
-
- return $this->options[$option];
+ return $this->getInt($option, $this->options, $default);
}
+
/**
* @param int $err
*
@@ -276,9 +279,8 @@ class Index implements IIndex, JsonSerializable {
return array_values(array_slice($this->errors, -1))[0];
}
-
/**
- *
+ * @return IIndex
*/
public function resetErrors(): IIndex {
$this->setErrors([]);
@@ -351,9 +353,9 @@ class Index implements IIndex, JsonSerializable {
/**
- * @return array<string,string|integer>
+ * @return array
*/
- public function jsonSerialize() {
+ public function jsonSerialize(): array {
return [
'ownerId' => $this->getOwnerId(),
'providerId' => $this->getProviderId(),
@@ -368,14 +370,18 @@ class Index implements IIndex, JsonSerializable {
}
+ /**
+ *
+ */
public function __destruct() {
unset($this->providerId);
unset($this->documentId);
+ unset($this->source);
unset($this->ownerId);
unset($this->status);
unset($this->options);
unset($this->err);
- unset($this->message);
+ unset($this->errors);
unset($this->lastIndex);
}
diff --git a/lib/Model/IndexOptions.php b/lib/Model/IndexOptions.php
index 1261bab..e5fdd25 100644
--- a/lib/Model/IndexOptions.php
+++ b/lib/Model/IndexOptions.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,24 +27,42 @@
*
*/
+
namespace OCA\FullTextSearch\Model;
+use daita\MySmallPhpTools\Traits\TArrayTools;
use JsonSerializable;
use OCP\FullTextSearch\Model\IIndexOptions;
+
+/**
+ * Class IndexOptions
+ *
+ * @package OCA\FullTextSearch\Model
+ */
class IndexOptions implements IIndexOptions, JsonSerializable {
+
+ use TArrayTools;
+
+
/**
* @var array
*/
private $options = [];
+ /**
+ * IndexOptions constructor.
+ *
+ * @param array $options
+ */
public function __construct($options = []) {
$this->options = $options;
}
+
/**
* @return array
*/
@@ -104,14 +125,9 @@ class IndexOptions implements IIndexOptions, JsonSerializable {
* @return string
*/
public function getOption(string $option, string $default = ''): string {
- if (array_key_exists($option, $this->options)) {
- return $this->options[$option];
- }
-
- return $default;
+ return $this->get($option, $this->options, $default);
}
-
/**
* @param string $option
* @param array $default
@@ -119,14 +135,7 @@ class IndexOptions implements IIndexOptions, JsonSerializable {
* @return array
*/
public function getOptionArray(string $option, array $default = []): array {
- if (array_key_exists($option, $this->options)) {
- $options = $this->options[$option];
- if (is_array($options)) {
- return $this->options[$option];
- }
- }
-
- return $default;
+ return $this->getArray($option, $this->options, $default);
}
@@ -137,21 +146,15 @@ class IndexOptions implements IIndexOptions, JsonSerializable {
* @return bool
*/
public function getOptionBool(string $option, bool $default): bool {
- if (array_key_exists($option, $this->options)) {
- $options = $this->options[$option];
- if (is_bool($options)) {
- return $this->options[$option];
- }
- }
-
- return $default;
+ return $this->getBool($option, $this->options, $default);
}
/**
* @return array
*/
- public function jsonSerialize() {
+ public function jsonSerialize(): array {
return $this->options;
}
}
+
diff --git a/lib/Model/PlatformWrapper.php b/lib/Model/PlatformWrapper.php
index 6a9673a..2c57dba 100644
--- a/lib/Model/PlatformWrapper.php
+++ b/lib/Model/PlatformWrapper.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -28,6 +31,7 @@
namespace OCA\FullTextSearch\Model;
+use OC\App\Platform;
use OCP\FullTextSearch\IFullTextSearchPlatform;
@@ -85,7 +89,7 @@ class PlatformWrapper {
/**
* @return string
*/
- public function getClass() {
+ public function getClass(): string {
return $this->class;
}
@@ -94,7 +98,7 @@ class PlatformWrapper {
*
* @return PlatformWrapper
*/
- public function setClass($class) {
+ public function setClass(string $class): PlatformWrapper {
$this->class = $class;
return $this;
@@ -104,7 +108,7 @@ class PlatformWrapper {
/**
* @return IFullTextSearchPlatform
*/
- public function getPlatform() {
+ public function getPlatform(): IFullTextSearchPlatform {
return $this->platform;
}
@@ -113,7 +117,7 @@ class PlatformWrapper {
*
* @return PlatformWrapper
*/
- public function setPlatform($platform) {
+ public function setPlatform(IFullTextSearchPlatform $platform): PlatformWrapper {
$this->platform = $platform;
return $this;
@@ -123,7 +127,7 @@ class PlatformWrapper {
/**
* @return string
*/
- public function getVersion() {
+ public function getVersion(): string {
return $this->version;
}
@@ -132,7 +136,7 @@ class PlatformWrapper {
*
* @return PlatformWrapper
*/
- public function setVersion($version) {
+ public function setVersion(string $version): PlatformWrapper {
$this->version = $version;
return $this;
diff --git a/lib/Model/ProviderIndexes.php b/lib/Model/ProviderIndexes.php
index 3177066..1475631 100644
--- a/lib/Model/ProviderIndexes.php
+++ b/lib/Model/ProviderIndexes.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -27,16 +30,24 @@
namespace OCA\FullTextSearch\Model;
+
use OCA\FullTextSearch\Exceptions\IndexDoesNotExistException;
use OCP\FullTextSearch\Model\IIndex;
+
+/**
+ * Class ProviderIndexes
+ *
+ * @package OCA\FullTextSearch\Model
+ */
class ProviderIndexes {
+
/** @var IIndex[] */
private $indexes;
- public function __construct($indexes) {
+ public function __construct(array $indexes) {
$this->indexes = $indexes;
}
@@ -44,7 +55,7 @@ class ProviderIndexes {
/**
* @return IIndex[]
*/
- public function getIndexes():array {
+ public function getIndexes(): array {
return $this->indexes;
}
diff --git a/lib/Model/ProviderWrapper.php b/lib/Model/ProviderWrapper.php
index d1de140..05ed653 100644
--- a/lib/Model/ProviderWrapper.php
+++ b/lib/Model/ProviderWrapper.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -55,7 +58,7 @@ class ProviderWrapper {
* @param string $appId
* @param IFullTextSearchProvider $provider
*/
- public function __construct($appId, $provider) {
+ public function __construct(string $appId, IFullTextSearchProvider $provider) {
$this->appId = $appId;
$this->provider = $provider;
}
@@ -63,7 +66,7 @@ class ProviderWrapper {
/**
* @return string
*/
- public function getAppId() {
+ public function getAppId(): string {
return $this->appId;
}
@@ -72,7 +75,7 @@ class ProviderWrapper {
*
* @return ProviderWrapper
*/
- public function setAppId($appId) {
+ public function setAppId(string $appId): ProviderWrapper {
$this->appId = $appId;
return $this;
@@ -82,7 +85,7 @@ class ProviderWrapper {
/**
* @return IFullTextSearchProvider
*/
- public function getProvider() {
+ public function getProvider(): IFullTextSearchProvider {
return $this->provider;
}
@@ -91,7 +94,7 @@ class ProviderWrapper {
*
* @return ProviderWrapper
*/
- public function setProvider($provider) {
+ public function setProvider(IFullTextSearchProvider $provider): ProviderWrapper {
$this->provider = $provider;
return $this;
@@ -101,7 +104,7 @@ class ProviderWrapper {
/**
* @return string
*/
- public function getVersion() {
+ public function getVersion(): string {
return $this->version;
}
@@ -110,7 +113,7 @@ class ProviderWrapper {
*
* @return ProviderWrapper
*/
- public function setVersion($version) {
+ public function setVersion(string $version): ProviderWrapper {
$this->version = $version;
return $this;
@@ -118,3 +121,4 @@ class ProviderWrapper {
}
+
diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php
index 37ae39c..ac78684 100644
--- a/lib/Model/Runner.php
+++ b/lib/Model/Runner.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -27,6 +30,8 @@
namespace OCA\FullTextSearch\Model;
+
+use daita\MySmallPhpTools\Traits\TArrayTools;
use OCA\FullTextSearch\ACommandBase;
use OCA\FullTextSearch\Exceptions\RunnerAlreadyUpException;
use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
@@ -38,8 +43,17 @@ use OCP\FullTextSearch\Model\IRunner;
use Symfony\Component\Console\Output\OutputInterface;
+/**
+ * Class Runner
+ *
+ * @package OCA\FullTextSearch\Model
+ */
class Runner implements IRunner {
+
+ use TArrayTools;
+
+
const TICK_TTL = 1800;
const TICK_MINIMUM = 2;
@@ -52,9 +66,6 @@ class Runner implements IRunner {
/** @var string */
private $source;
-// /** @var bool */
-// private $strict = false;
-
/** @var int */
private $tickId;
@@ -108,7 +119,7 @@ class Runner implements IRunner {
* @param string $source
* @param array $keys
*/
- public function __construct(RunningService $runningService, $source, $keys = []) {
+ public function __construct(RunningService $runningService, string $source, array $keys = []) {
$this->runningService = $runningService;
$this->source = $source;
@@ -122,7 +133,6 @@ class Runner implements IRunner {
* @throws RunnerAlreadyUpException
*/
public function start() {
-// $this->strict = $strict;
$this->tickId = $this->runningService->start($this->source);
}
@@ -167,7 +177,9 @@ class Runner implements IRunner {
}
usleep(300000);
- $this->base->abort();
+ if ($this->base !== null) {
+ $this->base->abort();
+ }
}
$this->pauseRunning(false);
@@ -205,7 +217,6 @@ class Runner implements IRunner {
*/
public function setInfoArray(array $data) {
$keys = array_keys($data);
- //$this->info['info'] = '';
foreach ($keys as $k) {
$this->info[$k] = $data[$k];
}
@@ -243,39 +254,37 @@ class Runner implements IRunner {
if ($color !== '') {
$this->info[$info . 'Colored'] = '<' . $color . '>' . $value . '</' . $color . '>';
}
-
-
}
/**
* @return array
*/
- public function getInfoAll() {
+ public function getInfoAll(): array {
return $this->info;
}
/**
- * @param string $k
+ * @param string $info
*
* @return string
*/
- public function getInfo($k) {
- return MiscService::get($k, $this->info, '');
+ public function getInfo(string $info): string {
+ return $this->get($info, $this->info, '');
}
/**
* @param array $method
*/
- public function onKeyPress($method) {
+ public function onKeyPress(array $method) {
$this->methodOnKeyPress[] = $method;
}
/**
- * @param $key
+ * @param string $key
*/
- public function keyPressed($key) {
+ public function keyPressed(string $key) {
foreach ($this->methodOnKeyPress as $method) {
call_user_func($method, $key);
}
@@ -285,11 +294,14 @@ class Runner implements IRunner {
/**
* @param array $method
*/
- public function onInfoUpdate($method) {
+ public function onInfoUpdate(array $method) {
$this->methodOnInfoUpdate[] = $method;
}
+ /**
+ *
+ */
public function infoUpdated() {
foreach ($this->methodOnInfoUpdate as $method) {
call_user_func($method, $this->info);
@@ -300,7 +312,7 @@ class Runner implements IRunner {
/**
* @param array $method
*/
- public function onNewIndexError($method) {
+ public function onNewIndexError(array $method) {
$this->methodOnIndexError[] = $method;
}
@@ -328,7 +340,7 @@ class Runner implements IRunner {
/**
* @param array $method
*/
- public function onNewIndexResult($method) {
+ public function onNewIndexResult(array $method) {
$this->methodOnIndexResult[] = $method;
}
@@ -359,7 +371,7 @@ class Runner implements IRunner {
*
* @throws TickDoesNotExistException
*/
- private function updateTick($tick, $action) {
+ private function updateTick(int $tick, string $action) {
if ($this->oldAction === $action && ($this->tickUpdate + self::TICK_UPDATE > $tick)) {
return;
}
@@ -376,9 +388,9 @@ class Runner implements IRunner {
/**
- * @param $tick
+ * @param int $tick
*/
- private function updateRamInfo($tick) {
+ private function updateRamInfo(int $tick) {
if (($this->ramUpdate + self::MEMORY_UPDATE) > $tick) {
return;
}
@@ -424,7 +436,7 @@ class Runner implements IRunner {
/**
* @param bool $pause
*/
- public function pause($pause) {
+ public function pause(bool $pause) {
$this->paused = $pause;
$this->infoUpdated();
}
@@ -432,7 +444,7 @@ class Runner implements IRunner {
/**
* @return bool
*/
- public function isPaused() {
+ public function isPaused(): bool {
return $this->paused;
}
@@ -440,13 +452,15 @@ class Runner implements IRunner {
/**
* @param bool $running
*/
- public function pauseRunning($running) {
+ public function pauseRunning(bool $running) {
$this->pauseRunning = $running;
$this->infoUpdated();
}
-
- public function isPauseRunning() {
+ /**
+ * @return bool
+ */
+ public function isPauseRunning(): bool {
return $this->pauseRunning;
}
@@ -454,7 +468,7 @@ class Runner implements IRunner {
/**
* @param string $line
*/
- public function output($line) {
+ public function output(string $line) {
if ($this->outputInterface === null) {
return;
}
diff --git a/lib/Model/SearchRequest.php b/lib/Model/SearchRequest.php
index f5730be..bc98d05 100644
--- a/lib/Model/SearchRequest.php
+++ b/lib/Model/SearchRequest.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,14 +27,26 @@
*
*/
+
namespace OCA\FullTextSearch\Model;
+
+use daita\MySmallPhpTools\Traits\TArrayTools;
use JsonSerializable;
-use OCA\FullTextSearch\Service\MiscService;
use OCP\FullTextSearch\Model\ISearchRequest;
+
+/**
+ * Class SearchRequest
+ *
+ * @package OCA\FullTextSearch\Model
+ */
class SearchRequest implements ISearchRequest, JsonSerializable {
+
+ use TArrayTools;
+
+
/** @var array */
private $providers;
@@ -316,11 +331,7 @@ class SearchRequest implements ISearchRequest, JsonSerializable {
* @return string
*/
public function getOption(string $option, string $default = ''): string {
- if (array_key_exists($option, $this->options)) {
- return $this->options[$option];
- }
-
- return $default;
+ return $this->get($option, $this->options, $default);
}
@@ -331,14 +342,7 @@ class SearchRequest implements ISearchRequest, JsonSerializable {
* @return array
*/
public function getOptionArray(string $option, array $default = []): array {
- if (array_key_exists($option, $this->options)) {
- $options = $this->options[$option];
- if (is_array($options)) {
- return $this->options[$option];
- }
- }
-
- return $default;
+ return $this->getArray($option, $this->options, $default);
}
@@ -648,7 +652,7 @@ class SearchRequest implements ISearchRequest, JsonSerializable {
/**
* @return array
*/
- public function jsonSerialize() {
+ public function jsonSerialize(): array {
return [
'providers' => $this->getProviders(),
'author' => $this->getAuthor(),
@@ -665,39 +669,41 @@ class SearchRequest implements ISearchRequest, JsonSerializable {
/**
- * @param string $json
- *
- * @return SearchRequest
- */
- public static function fromJSON(string $json): SearchRequest {
- return self::fromArray(json_decode($json, true));
- }
-
- /**
* @param array $arr
*
* @return SearchRequest
*/
- public static function fromArray($arr): SearchRequest {
+ public function importFromArray($arr): SearchRequest {
$providers = $arr['providers'];
if (!is_array($providers)) {
$providers = [$providers];
}
- $request = new SearchRequest();
- $request->setProviders($providers);
- $request->setAuthor(MiscService::get('author', $arr, ''));
- $request->setSearch(MiscService::get('search', $arr, ''));
- $request->setPage(MiscService::get('page', $arr, 0));
- $request->setParts(MiscService::get('parts', $arr, []));
- $request->setSize(MiscService::get('size', $arr, 10));
- $request->setOptions(MiscService::get('options', $arr, []));
- $request->setMetaTags(MiscService::get('metatags', $arr, []));
- $request->setSubTags(MiscService::get('subtags', $arr, []));
- $request->setTags(MiscService::get('tags', $arr, []));
+ $this->setProviders($providers);
+ $this->setAuthor($this->get('author', $arr, ''));
+ $this->setSearch($this->get('search', $arr, ''));
+ $this->setPage($this->getInt('page', $arr, 0));
+ $this->setParts($this->getArray('parts', $arr, []));
+ $this->setSize($this->getInt('size', $arr, 10));
+ $this->setOptions($this->getArray('options', $arr, []));
+ $this->setMetaTags($this->getArray('metatags', $arr, []));
+ $this->setSubTags($this->getArray('subtags', $arr, []));
+ $this->setTags($this->getArray('tags', $arr, []));
- return $request;
+ return $this;
}
+ /**
+ * @param string $json
+ *
+ * @return SearchRequest
+ */
+ public static function fromJSON(string $json): SearchRequest {
+ $searchRequest = new SearchRequest();
+ $searchRequest->importFromArray(json_decode($json, true));
+
+ return $searchRequest;
+ }
+
}
diff --git a/lib/Model/SearchResult.php b/lib/Model/SearchResult.php
index f51a7f0..4d77445 100644
--- a/lib/Model/SearchResult.php
+++ b/lib/Model/SearchResult.php
@@ -30,6 +30,7 @@ declare(strict_types=1);
namespace OCA\FullTextSearch\Model;
+
use JsonSerializable;
use OCP\FullTextSearch\IFullTextSearchPlatform;
use OCP\FullTextSearch\IFullTextSearchProvider;
@@ -38,6 +39,11 @@ use OCP\FullTextSearch\Model\ISearchRequest;
use OCP\FullTextSearch\Model\ISearchResult;
+/**
+ * Class SearchResult
+ *
+ * @package OCA\FullTextSearch\Model
+ */
class SearchResult implements ISearchResult, JsonSerializable {
/** @var IndexDocument[] */
@@ -68,7 +74,12 @@ class SearchResult implements ISearchResult, JsonSerializable {
private $request;
- public function __construct(SearchRequest $searchRequest = null) {
+ /**
+ * SearchResult constructor.
+ *
+ * @param SearchRequest $searchRequest
+ */
+ public function __construct(SearchRequest $searchRequest) {
$this->request = $searchRequest;
}
@@ -160,7 +171,7 @@ class SearchResult implements ISearchResult, JsonSerializable {
*
* @return ISearchResult
*/
- public function setPlatform($platform): ISearchResult {
+ public function setPlatform(IFullTextSearchPlatform $platform): ISearchResult {
$this->platform = $platform;
return $this;
@@ -263,9 +274,38 @@ class SearchResult implements ISearchResult, JsonSerializable {
/**
- * @return array<string,array<string,string>|IndexDocument[]|integer>
+ * @since 15.0.0
+ *
+ * @param string $category
+ * @param string $value
+ * @param int $count
+ *
+ * @return ISearchResult
*/
- public function jsonSerialize() {
+ public function addAggregation(string $category, string $value, int $count): ISearchResult {
+ // TODO: Implement addAggregation() method.
+
+ return $this;
+ }
+
+ /**
+ * @since 15.0.0
+ *
+ * @param string $category
+ *
+ * @return array
+ */
+ public function getAggregations(string $category): array {
+ // TODO: Implement getAggregations() method.
+
+ return [];
+ }
+
+
+ /**
+ * @return array
+ */
+ public function jsonSerialize(): array {
$providerObj = $this->getProvider();
$provider = [];
@@ -300,31 +340,5 @@ class SearchResult implements ISearchResult, JsonSerializable {
];
}
- /**
- * @since 15.0.0
- *
- * @param string $category
- * @param string $value
- * @param int $count
- *
- * @return ISearchResult
- */
- public function addAggregation(string $category, string $value, int $count): ISearchResult {
- // TODO: Implement addAggregation() method.
-
- return $this;
- }
-
- /**
- * @since 15.0.0
- *
- * @param string $category
- *
- * @return array
- */
- public function getAggregations(string $category): array {
- // TODO: Implement getAggregations() method.
-
- return [];
- }
}
+
diff --git a/lib/Model/Tick.php b/lib/Model/Tick.php
index bd7649d..46bb7b2 100644
--- a/lib/Model/Tick.php
+++ b/lib/Model/Tick.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -28,8 +31,19 @@
namespace OCA\FullTextSearch\Model;
+use daita\MySmallPhpTools\Traits\TArrayTools;
+
+/**
+ * Class Tick
+ *
+ * @package OCA\FullTextSearch\Model
+ */
class Tick {
+
+ use TArrayTools;
+
+
/** @var int */
private $id;
@@ -52,7 +66,13 @@ class Tick {
private $action;
- public function __construct($source, $id = 0) {
+ /**
+ * Tick constructor.
+ *
+ * @param string $source
+ * @param int $id
+ */
+ public function __construct(string $source, int $id = 0) {
$this->source = $source;
$this->id = $id;
}
@@ -61,7 +81,7 @@ class Tick {
/**
* @return int
*/
- public function getId() {
+ public function getId(): int {
return $this->id;
}
@@ -70,7 +90,7 @@ class Tick {
*
* @return $this
*/
- public function setId($id) {
+ public function setId(int $id): Tick {
$this->id = $id;
return $this;
@@ -80,7 +100,7 @@ class Tick {
/**
* @return string
*/
- public function getSource() {
+ public function getSource(): string {
return $this->source;
}
@@ -88,7 +108,7 @@ class Tick {
/**
* @return array
*/
- public function getData() {
+ public function getData(): array {
return $this->data;
}
@@ -97,7 +117,7 @@ class Tick {
*
* @return $this
*/
- public function setData($data) {
+ public function setData(array $data): Tick {
$this->data = $data;
return $this;
@@ -107,7 +127,7 @@ class Tick {
/**
* @return int
*/
- public function getTick() {
+ public function getTick(): int {
return $this->tick;
}
@@ -116,7 +136,7 @@ class Tick {
*
* @return $this
*/
- public function setTick($tick = 0) {
+ public function setTick(int $tick = 0): Tick {
if ($tick === 0) {
$tick = time();
}
@@ -130,7 +150,7 @@ class Tick {
/**
* @return int
*/
- public function getFirstTick() {
+ public function getFirstTick(): int {
return $this->firstTick;
}
@@ -139,7 +159,7 @@ class Tick {
*
* @return $this
*/
- public function setFirstTick($tick = 0) {
+ public function setFirstTick(int $tick = 0): Tick {
if ($tick === 0) {
$tick = time();
}
@@ -153,7 +173,7 @@ class Tick {
/**
* @return string
*/
- public function getStatus() {
+ public function getStatus(): string {
return $this->status;
}
@@ -162,7 +182,7 @@ class Tick {
*
* @return $this
*/
- public function setStatus($status) {
+ public function setStatus(string $status): Tick {
$this->status = $status;
return $this;
@@ -172,7 +192,7 @@ class Tick {
/**
* @return string
*/
- public function getAction() {
+ public function getAction(): string {
return $this->action;
}
@@ -181,7 +201,7 @@ class Tick {
*
* @return $this
*/
- public function setAction($action) {
+ public function setAction(string $action): Tick {
$this->action = $action;
return $this;
@@ -189,33 +209,56 @@ class Tick {
/**
- * @param string $key
- * @param string|int $value
+ * @param string $info
+ * @param string $value
+ *
+ * @return $this
+ */
+ public function setInfo(string $info, string $value): Tick {
+ $this->data[$info] = $value;
+
+ return $this;
+ }
+
+ /**
+ * @param string $info
+ * @param int $value
*
* @return $this
*/
- public function setInfo($key, $value) {
- $this->data[$key] = $value;
+ public function setInfoInt(string $info, int $value): Tick {
+ $this->data[$info] = $value;
return $this;
}
- public function unsetInfo($key) {
- unset($this->data[$key]);
+ /**
+ * @param string $info
+ */
+ public function unsetInfo(string $info) {
+ unset($this->data[$info]);
}
/**
- * @param $key
- * @param int|string $default
+ * @param string $info
+ * @param string $default
*
- * @return int|string
+ * @return string
*/
- public function getInfo($key, $default = '') {
- if (!array_key_exists($key, $this->data)) {
- return $default;
- }
+ public function getInfo(string $info, string $default = ''): string {
+ return $this->get($info, $this->data, $default);
+ }
- return $this->data[$key];
+ /**
+ * @param string $info
+ * @param int $default
+ *
+ * @return int
+ */
+ public function getInfoInt(string $info, int $default = 0): int {
+ return $this->getInt($info, $this->data, $default);
}
+
}
+