Issues (1)

src/Review.php (1 issue)

Labels
Severity
1
<?php
2
namespace exussum12\TripAdvisor;
3
4
use DateTimeImmutable;
5
use DateTimeInterface;
6
7
/**
8
 * @property string reviewReference
9
 * @property string listingReference
10
 * @property string externalListingReference
11
 * @property bool isDeleted
12
 * @property DateTimeInterface reviewDate
13
 * @property DateTimeInterface|null visitDate
14
 * @property string title
15
 * @property string text
16
 * @property string reviewLanguage
17
 * @property string managementResponse
18
 * @property string responseLanguage
19
 * @property double rating
20
 * @property string authorName
21
 * @property string authorLocation
22
 * @property string accountReference
23
 * @property string externalAccountReference
24
 */
25
class Review
26
{
27
    protected $review;
28
    public function __construct($review)
29
    {
30
        $this->changeAllToString($review);
31
        $this->review = $review;
32
        $this->applyCorrectTypes();
33
    }
34
35
    public function __get($name)
36
    {
37
        return $this->review->$name;
38
    }
39
40
    public function __set($variable, $value)
41
    {
42
        throw new Exceptions\ImmutableObjectException();
43
    }
44
45
    protected function applyCorrectTypes()
46
    {
47
        if (isset($this->review->reviewDate)) {
48
            $this->review->reviewDate = new DateTimeImmutable($this->reviewDate);
0 ignored issues
show
$this->reviewDate of type DateTimeInterface is incompatible with the type string expected by parameter $datetime of DateTimeImmutable::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
            $this->review->reviewDate = new DateTimeImmutable(/** @scrutinizer ignore-type */ $this->reviewDate);
Loading history...
49
        }
50
51
        if (isset($this->review->visitDate)) {
52
            $this->review->visitDate = new DateTimeImmutable($this->visitDate);
53
        }
54
55
        if (isset($this->review->isDeleted)) {
56
            $this->review->isDelted = (bool) $this->isDeleted;
57
        }
58
        if (isset($this->review->rating)) {
59
            $this->review->rating = (double) $this->rating;
60
        }
61
    }
62
63
    protected function changeAllToString($review)
64
    {
65
        foreach ($review as &$part) {
66
            $part = (string) $part;
67
        }
68
    }
69
}
70