Skip to content

Commit 4ae5d9b

Browse files
committed
Updated Libs.Entity classes docs.
1 parent 75d701b commit 4ae5d9b

File tree

2 files changed

+140
-52
lines changed

2 files changed

+140
-52
lines changed

src/Libs/Entity/StateEntity.php

+83
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,75 @@ final class StateEntity implements iState
1313
{
1414
use LoggerAwareTrait;
1515

16+
/**
17+
* @var array $data Holds the original entity data.
18+
*/
1619
private array $data = [];
20+
/**
21+
* @var bool $tainted Flag indicating if the data is tainted based on its event type.
22+
*/
1723
private bool $tainted = false;
1824

25+
/**
26+
* @var string|int|null $id The corresponding database id.
27+
*/
1928
public null|string|int $id = null;
29+
30+
/**
31+
* @var string $type What type of data this entity holds.
32+
*/
2033
public string $type = '';
34+
/**
35+
* @var int $updated When was the entity last updated.
36+
*/
2137
public int $updated = 0;
38+
39+
/**
40+
* @var int $watched Whether the entity is watched or not.
41+
*/
2242
public int $watched = 0;
2343

44+
/**
45+
* @var string $via The backend that this entity data belongs to.
46+
*/
2447
public string $via = '';
48+
49+
/**
50+
* @var string $title The title of the entity usually in format of "Movie Title (Year)" if event type is movie. Or "Series Title (Year) - Season x Episode" if event type is episode.
51+
*/
2552
public string $title = '';
2653

54+
/**
55+
* @var int|null $year The year of the entity.
56+
*/
2757
public int|null $year = null;
58+
/**
59+
* @var int|null $season The season number of the episode if event type is episode.
60+
*/
2861
public int|null $season = null;
62+
/**
63+
* @var int|null $episode The episode number of the episode event type is episode.
64+
*/
2965
public int|null $episode = null;
3066

67+
/**
68+
* @var array $parent The parent guids for this entity. Empty if event type is movie.
69+
*/
3170
public array $parent = [];
71+
72+
/**
73+
* @var array $guids The guids for this entity. Empty if event type is episode.
74+
*/
3275
public array $guids = [];
76+
77+
/**
78+
* @var array $metadata holds the metadata from various backends.
79+
*/
3380
public array $metadata = [];
81+
82+
/**
83+
* @var array $extra holds the extra data from various backends.
84+
*/
3485
public array $extra = [];
3586

3687
public function __construct(array $data)
@@ -455,6 +506,17 @@ public function getPlayProgress(): int
455506
return $lastProgress;
456507
}
457508

509+
/**
510+
* Checks if the value of a given key in the entity object is equal to the corresponding value in the current object.
511+
* Some keys are special and require special logic to compare. For example, the updated and watched keys are special
512+
* because they are tied together.
513+
*
514+
* @param string $key The key to check in the entity object.
515+
* @param iState $entity The entity object to compare the key value with.
516+
*
517+
* @return bool Returns true if the value of the key in the entity object is equal to the value in the current object,
518+
* otherwise returns false.
519+
*/
458520
private function isEqualValue(string $key, iState $entity): bool
459521
{
460522
if (iState::COLUMN_UPDATED === $key || iState::COLUMN_WATCHED === $key) {
@@ -468,6 +530,17 @@ private function isEqualValue(string $key, iState $entity): bool
468530
return true;
469531
}
470532

533+
/**
534+
* Updates the value of a given key in the current object with the corresponding value from the remote object.
535+
* The method follows certain logic for specific keys such as "updated" and "watched". For these keys, if the remote
536+
* object has a greater "updated" value and a different "watched" value compared to the current object, the values in
537+
* the current object are updated with the values from the remote object. If the key is an array column the method uses
538+
* the recursive replacement to update the value of the key in the current object with the value from the remote
539+
* object. Otherwise, it simply assigns the value of the key from the remote object to the current object.
540+
*
541+
* @param string $key The key to update in the current object.
542+
* @param iState $remote The remote object to get the updated value from.
543+
*/
471544
private function updateValue(string $key, iState $remote): void
472545
{
473546
if (iState::COLUMN_UPDATED === $key || iState::COLUMN_WATCHED === $key) {
@@ -490,6 +563,16 @@ private function updateValue(string $key, iState $remote): void
490563
}
491564
}
492565

566+
/**
567+
* Calculates the difference between two arrays by comparing their values recursively.
568+
*
569+
* @param array $oldArray The original array to compare.
570+
* @param array $newArray The new array to compare.
571+
*
572+
* @return array Returns an associative array that contains the differences between the two arrays. The keys are the
573+
* differing elements from the new array, and the values are arrays that contain the old and new values
574+
* for each differing element.
575+
*/
493576
private function arrayDiff(array $oldArray, array $newArray): array
494577
{
495578
$difference = [];

0 commit comments

Comments
 (0)