Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
DatabaseResultBase
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getResultCount
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 mappingImpl
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\Core\Database;
6
7use PeServer\Core\Serialization\IMapper;
8use PeServer\Core\Serialization\Mapper;
9
10/**
11 * 問い合わせ結果格納データ基底。
12 */
13abstract class DatabaseResultBase
14{
15    /**
16     * 生成。
17     *
18     * @param DatabaseColumn[] $columns カラム情報(取得成功したものだけ格納されている)。
19     * @param int $resultCount 実行影響件数。
20     * @phpstan-param non-negative-int $resultCount
21     */
22    public function __construct(
23        public readonly array $columns,
24        private readonly int $resultCount
25    ) {
26    }
27
28    #region function
29
30    /**
31     * 実行影響件数を取得。
32     *
33     * @return int
34     * @phpstan-return non-negative-int
35     */
36    public function getResultCount(): int
37    {
38        return $this->resultCount;
39    }
40
41    /**
42     * 行データに対してオブジェクトマッピング処理。
43     *
44     * 上位でとりあえずいい感じにしとく感じで。
45     *
46     * @template TFieldArray of FieldArrayAlias
47     * @template TObject of object
48     * @param array $fields
49     * @phpstan-param TFieldArray $fields
50     * @param string|object $classNameOrObject
51     * @phpstan-param class-string<TObject>|TObject $classNameOrObject
52     * @param IMapper $mapper マッピング処理。
53     * @return object
54     * @phpstan-return TObject
55     */
56    protected function mappingImpl(array $fields, string|object $classNameOrObject, IMapper $mapper): object
57    {
58        $object = is_string($classNameOrObject)
59            ? new $classNameOrObject()
60            : $classNameOrObject;
61
62        $mapper->mapping($fields, $object);
63
64        return $object;
65    }
66
67    //public abstract function mapping(string|object $classNameOrObject, IMapper $mapper = null): mixed;
68
69    #endregion
70}