PluginProbe
Packeta / 2.1
Packeta v2.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | src/Packetery/Module/Log/DbLogger.php +18 -34 1.6.42.1 View file →
@@ -6,12 +6,12 @@
6 6 */
7 7
8 8 declare( strict_types=1 );
9 9
10 -
11 10 namespace Packetery\Module\Log;
12 11
13 -use Packetery\Core\Helper;
12 +use Packetery\Core\CoreHelper;
13 +use Packetery\Core\Log\ILogger;
14 14 use Packetery\Core\Log\Record;
15 15
16 16 /**
17 17 * Class DbLogger
@@ -17,9 +17,9 @@
17 17 * Class DbLogger
18 18 *
19 19 * @package Packetery\Module\Log
20 20 */
21 -class DbLogger implements \Packetery\Core\Log\ILogger {
21 +class DbLogger implements ILogger {
22 22
23 23 /**
24 24 * Log repository.
25 25 *
@@ -35,27 +35,11 @@
35 35 public function __construct( Repository $logRepository ) {
36 36 $this->logRepository = $logRepository;
37 37 }
38 38
39 - /**
40 - * Registers logger.
41 - *
42 - * @return void
43 - */
44 - public function register(): void {
45 - }
46 -
47 - /**
48 - * Adds record.
49 - *
50 - * @param Record $record Record.
51 - *
52 - * @return void
53 - * @throws \Exception From DateTimeImmutable.
54 - */
55 39 public function add( Record $record ): void {
56 - if ( null === $record->date ) {
57 - $record->date = Helper::now();
40 + if ( $record->date === null ) {
41 + $record->date = CoreHelper::now();
58 42 }
59 43
60 44 $this->logRepository->save( $record );
61 45 }
@@ -62,17 +46,17 @@
62 46
63 47 /**
64 48 * Gets records.
65 49 *
66 - * @param mixed $orderId Order ID.
67 - * @param string|null $action Action.
68 - * @param array $sorting Sorting config.
69 - * @param int $limit Limit.
50 + * @param int|null $orderId Order ID.
51 + * @param string|null $action Action.
52 + * @param array<string, string> $sorting Sorting config.
53 + * @param int $limit Limit.
70 54 *
71 - * @return iterable|Record[]
55 + * @return \Generator<Record>|array{}
72 56 * @throws \Exception From DateTimeImmutable.
73 57 */
74 - public function getRecords( $orderId, ?string $action, array $sorting = [], int $limit = 100 ): iterable {
58 + public function getRecords( ?int $orderId, ?string $action, array $sorting = [], int $limit = 100 ): iterable {
75 59 $arguments = [
76 60 'orderby' => $sorting,
77 61 'limit' => $limit,
78 62 ];
@@ -79,14 +63,14 @@
79 63
80 64 if ( is_numeric( $orderId ) ) {
81 65 $arguments['order_id'] = $orderId;
82 66 }
83 - if ( null !== $action ) {
67 + if ( $action !== null ) {
84 68 $arguments['action'] = $action;
85 69 }
86 70
87 71 $logs = $this->logRepository->find( $arguments );
88 - if ( ! $logs ) {
72 + if ( ! $logs instanceof \Generator ) {
89 73 return [];
90 74 }
91 75
92 76 return $logs;
@@ -99,9 +83,9 @@
99 83 * @param string|null $action Action.
100 84 *
101 85 * @return int
102 86 */
103 - public function countRecords( $orderId = null, ?string $action = null ): int {
87 + public function countRecords( ?int $orderId = null, ?string $action = null ): int {
104 88 return $this->logRepository->countRows( $orderId, $action );
105 89 }
106 90
107 91 /**
@@ -106,14 +90,14 @@
106 90
107 91 /**
108 92 * Gets logs for given period as array.
109 93 *
110 - * @param array $dateQuery Date_query compatible array.
94 + * @param array<array<string, string>> $dateQuery Date_query compatible array.
111 95 *
112 - * @return array
96 + * @return \Generator<Record>|array{}
113 97 * @throws \Exception From DateTimeImmutable.
114 98 */
115 - public function getForPeriodAsArray( array $dateQuery ): iterable {
99 + public function getForPeriodAsArray( array $dateQuery ) {
116 100 $arguments = [
117 101 'orderby' => [ 'date' => 'ASC' ],
118 102 'date_query' => $dateQuery,
119 103 ];
@@ -118,9 +102,9 @@
118 102 'date_query' => $dateQuery,
119 103 ];
120 104
121 105 $logs = $this->logRepository->find( $arguments );
122 - if ( ! $logs ) {
106 + if ( ! $logs instanceof \Generator ) {
123 107 return [];
124 108 }
125 109
126 110 return $logs;