• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

plank / laravel-metable / 8731108978

18 Apr 2024 01:38AM UTC coverage: 92.361% (-6.4%) from 98.76%
8731108978

Pull #102

github

frasmage
added metable:refresh artisan command
Pull Request #102: V6

215 of 248 new or added lines in 18 files covered. (86.69%)

26 existing lines in 7 files now uncovered.

399 of 432 relevant lines covered (92.36%)

65.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/DataType/ModelHandler.php
1
<?php
2

3
namespace Plank\Metable\DataType;
4

5
use Illuminate\Database\Eloquent\Model;
6

7
/**
8
 * Handle serialization of Eloquent Models.
9
 */
10
class ModelHandler implements HandlerInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function getDataType(): string
16
    {
17
        return 'model';
276✔
18
    }
19

20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function canHandleValue(mixed $value): bool
24
    {
25
        return $value instanceof Model;
24✔
26
    }
27

28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function serializeValue(mixed $value): string
32
    {
33
        if ($value->exists) {
18✔
34
            return get_class($value) . '#' . $value->getKey();
12✔
35
        }
36

37
        return get_class($value);
6✔
38
    }
39

40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function unserializeValue(string $serializedValue): mixed
44
    {
45
        // Return blank instances.
46
        if (strpos($serializedValue, '#') === false) {
18✔
47
            return new $serializedValue();
6✔
48
        }
49

50
        // Fetch specific instances.
51
        /** @var class-string<Model> $class */
52
        [$class, $id] = explode('#', $serializedValue);
12✔
53
        if (!is_a($class, Model::class, true)) {
12✔
54
            return null;
6✔
55
        }
56

57
        return $class::query()->find($id);
6✔
58
    }
59

60
    public function getNumericValue(mixed $value): null|int|float
61
    {
62
        return null;
12✔
63
    }
64

65
    public function getStringValue(mixed $value): null|string
66
    {
67
        return $this->serializeValue($value);
12✔
68
    }
69

70
    public function isIdempotent(): bool
71
    {
NEW
UNCOV
72
        return true;
×
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc