Skip to content

Commit ce8dcac

Browse files
authored
Update StyleCI config + fixes
1 parent c52ac9f commit ce8dcac

8 files changed

Lines changed: 149 additions & 27 deletions

File tree

.styleci.yml

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,90 @@
11
preset: psr12
2+
risky: true
3+
4+
version: 8
25

36
finder:
4-
exclude:
5-
- docs
6-
- vendor
7+
exclude:
8+
- docs
9+
- vendor
10+
- resources
11+
- views
12+
- public
13+
not-name:
14+
- UnionCar.php
15+
16+
enabled:
17+
- alpha_ordered_imports
18+
- alpha_ordered_traits
19+
- array_indentation
20+
- array_push
21+
- combine_consecutive_issets
22+
- combine_consecutive_unsets
23+
- combine_nested_dirname
24+
- declare_strict_types
25+
- dir_constant
26+
- final_static_access
27+
- fully_qualified_strict_types
28+
- function_to_constant
29+
- hash_to_slash_comment
30+
- is_null
31+
- logical_operators
32+
- magic_constant_casing
33+
- magic_method_casing
34+
- method_separation
35+
- modernize_types_casting
36+
- native_function_casing
37+
- native_function_type_declaration_casing
38+
- no_alias_functions
39+
- no_alternative_syntax
40+
- no_empty_comment
41+
- no_empty_phpdoc
42+
- no_empty_statement
43+
- no_extra_block_blank_lines
44+
- no_short_bool_cast
45+
- no_short_echo_tag
46+
- no_superfluous_elseif
47+
- no_unneeded_control_parentheses
48+
- no_unneeded_curly_braces
49+
- no_unneeded_final_method
50+
- no_unset_cast
51+
- no_unused_imports
52+
- no_unused_lambda_imports
53+
- no_useless_else
54+
- no_useless_return
55+
- normalize_index_brace
56+
- php_unit_dedicate_assert
57+
- php_unit_dedicate_assert_internal_type
58+
- php_unit_expectation
59+
- php_unit_mock
60+
- php_unit_mock_short_will_return
61+
- php_unit_namespaced
62+
- php_unit_no_expectation_annotation
63+
- phpdoc_no_empty_return
64+
- phpdoc_no_useless_inheritdoc
65+
- phpdoc_order
66+
- phpdoc_property
67+
- phpdoc_scalar
68+
- phpdoc_separation
69+
- phpdoc_singular_inheritdoc
70+
- phpdoc_trim
71+
- phpdoc_trim_consecutive_blank_line_separation
72+
- phpdoc_type_to_var
73+
- phpdoc_types
74+
- phpdoc_types_order
75+
- phpdoc_var_without_name
76+
- print_to_echo
77+
- regular_callable_call
78+
- return_assignment
79+
- self_accessor
80+
- self_static_accessor
81+
- set_type_to_cast
82+
- short_array_syntax
83+
- short_list_syntax
84+
- simplified_if_return
85+
- single_quote
86+
- standardize_not_equals
87+
- ternary_to_null_coalescing
88+
- trailing_comma_in_multiline_array
89+
- unalign_double_arrow
90+
- unalign_equals

src/Logger.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
namespace Yiisoft\Log;
66

7-
use Exception;
8-
use Psr\Log\InvalidArgumentException;
9-
use Psr\Log\LoggerInterface;
10-
use Psr\Log\LoggerTrait;
11-
use Psr\Log\LogLevel;
12-
use Throwable;
13-
use Yiisoft\VarDumper\VarDumper;
14-
157
use function array_filter;
168
use function count;
179
use function debug_backtrace;
10+
use Exception;
1811
use function get_class;
1912
use function is_scalar;
2013
use function is_string;
14+
2115
use function memory_get_usage;
2216
use function method_exists;
2317
use function preg_replace_callback;
18+
use Psr\Log\InvalidArgumentException;
19+
use Psr\Log\LoggerInterface;
20+
use Psr\Log\LoggerTrait;
21+
use Psr\Log\LogLevel;
2422
use function register_shutdown_function;
2523
use function strpos;
24+
use Throwable;
25+
use Yiisoft\VarDumper\VarDumper;
2626

2727
/**
2828
* Logger records logged messages in memory and sends them to different targets according to {@see Logger::$targets}.
@@ -108,7 +108,9 @@ public function __construct(array $targets = [])
108108

109109
/**
110110
* Returns the text display of the specified level.
111+
*
111112
* @param mixed $level the message level, e.g. {@see LogLevel::ERROR}, {@see LogLevel::WARNING}.
113+
*
112114
* @return string the text display of the level
113115
*/
114116
public static function getLevelName($level): string
@@ -129,6 +131,7 @@ public function getTargets(): array
129131

130132
/**
131133
* @param int|string $name string name or integer index
134+
*
132135
* @return Target|null
133136
*/
134137
public function getTarget($name): ?Target
@@ -152,6 +155,7 @@ public function setTargets(array $targets): void
152155

153156
/**
154157
* Adds extra target to {@see Logger::$targets}.
158+
*
155159
* @param Target $target the log target instance.
156160
* @param string|null $name array key to be used to store target, if `null` is given target will be append
157161
* to the end of the array by natural integer key.
@@ -191,6 +195,7 @@ public function log($level, $message, array $context = []): void
191195

192196
/**
193197
* Flushes log messages from memory to targets.
198+
*
194199
* @param bool $final whether this is a final call during a request.
195200
*/
196201
public function flush(bool $final = false): void
@@ -233,6 +238,7 @@ public function setExcludedTracePaths(array $excludedTracePaths): self
233238

234239
/**
235240
* Dispatches the logged messages to {@see Logger::$targets}.
241+
*
236242
* @param array $messages the logged messages
237243
* @param bool $final whether this method is called at the end of the current application
238244
*/
@@ -263,7 +269,9 @@ protected function dispatch(array $messages, bool $final): void
263269

264270
/**
265271
* Prepares message for logging.
272+
*
266273
* @param mixed $message
274+
*
267275
* @return string
268276
*/
269277
protected function prepareMessage($message): string
@@ -282,8 +290,10 @@ protected function prepareMessage($message): string
282290
/**
283291
* Parses log message resolving placeholders in the form: '{foo}', where foo
284292
* will be replaced by the context data in key "foo".
293+
*
285294
* @param string $message log message.
286295
* @param array $context message context.
296+
*
287297
* @return string parsed message.
288298
*/
289299
protected function parseMessage(string $message, array $context): string

src/PsrTarget.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class PsrTarget extends Target
1919

2020
/**
2121
* Sets the PSR-3 logger used to save messages of this target.
22+
*
2223
* @param LoggerInterface $logger logger instance.
2324
*/
2425
public function __construct(LoggerInterface $logger)

src/Target.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
namespace Yiisoft\Log;
66

7-
use DateTime;
8-
use Psr\Log\InvalidArgumentException;
9-
use Psr\Log\LogLevel;
10-
use Yiisoft\Arrays\ArrayHelper;
11-
use Yiisoft\VarDumper\VarDumper;
12-
137
use function array_merge;
148
use function count;
9+
use DateTime;
1510
use function implode;
1611
use function in_array;
12+
1713
use function is_array;
1814
use function is_callable;
1915
use function is_string;
16+
use Psr\Log\InvalidArgumentException;
17+
use Psr\Log\LogLevel;
2018
use function rtrim;
2119
use function strpos;
2220
use function substr_compare;
21+
use Yiisoft\Arrays\ArrayHelper;
22+
use Yiisoft\VarDumper\VarDumper;
2323

2424
/**
2525
* Target is the base class for all log target classes.
@@ -58,6 +58,7 @@ abstract class Target
5858
* You can use an asterisk at the end of a category so that the category can be used to
5959
* match those categories sharing the same common prefix. For example, 'Yiisoft\Db\*' will match
6060
* categories starting with 'Yiisoft\Db\', such as `Yiisoft\Db\Connection`.
61+
*
6162
* @see categories
6263
*/
6364
private array $except = [];
@@ -143,6 +144,7 @@ abstract public function export(): void;
143144
* Processes the given log messages.
144145
* This method will filter the given messages with {@see Target::$levels} and {@see Target::$categories}.
145146
* And if requested, it will also export the filtering result to specific medium (e.g. email).
147+
*
146148
* @param array $messages log messages to be processed. See {@see Logger::$messages} for the structure
147149
* of each message.
148150
* @param bool $final whether this method is called at the end of the current application
@@ -162,8 +164,8 @@ public function collect(array $messages, bool $final): void
162164
$context,
163165
[
164166
'category' => static::DEFAULT_CATEGORY,
165-
'time' => $_SERVER['REQUEST_TIME_FLOAT'] ?? \microtime(true)
166-
]
167+
'time' => $_SERVER['REQUEST_TIME_FLOAT'] ?? \microtime(true),
168+
],
167169
];
168170
}
169171
// set exportInterval to 0 to avoid triggering export again while exporting
@@ -179,6 +181,7 @@ public function collect(array $messages, bool $final): void
179181
/**
180182
* Generates the context information to be logged.
181183
* The default implementation will dump user information, system variables, etc.
184+
*
182185
* @return string the context information. If an empty string, it means no context information.
183186
*/
184187
protected function getContextMessage(): string
@@ -194,12 +197,15 @@ protected function getContextMessage(): string
194197

195198
/**
196199
* Filters the given messages according to their categories and levels.
200+
*
197201
* @param array $messages messages to be filtered. The message structure follows that in {@see Logger::$messages}.
198202
* @param array $levels the message levels to filter by. Empty value means allowing all levels.
199203
* @param array $categories the message categories to filter by. If empty, it means all categories are allowed.
200204
* @param array $except the message categories to exclude. If empty, it means all categories are allowed.
201-
* @return array the filtered messages.
205+
*
202206
* @throws InvalidArgumentException for invalid message structure.
207+
*
208+
* @return array the filtered messages.
203209
*/
204210
protected function filterMessages(
205211
array $messages,
@@ -255,7 +261,9 @@ protected function filterMessages(
255261

256262
/**
257263
* Checks message structure {@see Logger::$messages}.
264+
*
258265
* @param mixed $message the log message to be checked.
266+
*
259267
* @throws InvalidArgumentException for invalid message structure.
260268
*/
261269
protected function checkMessageStructure($message): void
@@ -267,10 +275,13 @@ protected function checkMessageStructure($message): void
267275

268276
/**
269277
* Formats a log message for display as a string.
278+
*
270279
* @param array $message the log message to be formatted.
271280
* The message structure follows that in {@see Logger::$messages}.
272-
* @return string the formatted message.
281+
*
273282
* @throws InvalidArgumentException for invalid message structure.
283+
*
284+
* @return string the formatted message.
274285
*/
275286
protected function formatMessage(array $message): string
276287
{
@@ -300,8 +311,10 @@ protected function formatMessage(array $message): string
300311
* Returns a string to be prefixed to the given message.
301312
* If {@see Target::$prefix} is configured it will return the result of the callback.
302313
* The default implementation will return user IP, user ID and session ID as a prefix.
314+
*
303315
* @param array $message the message being exported.
304316
* The message structure follows that in {@see Logger::$messages}.
317+
*
305318
* @return string the prefix string
306319
*/
307320
protected function getMessagePrefix(array $message): string
@@ -315,7 +328,9 @@ protected function getMessagePrefix(array $message): string
315328

316329
/**
317330
* Returns formatted timestamp for message, according to {@see Target::$timestampFormat}
331+
*
318332
* @param float|int $timestamp
333+
*
319334
* @return string
320335
*/
321336
protected function getTime($timestamp): string
@@ -327,6 +342,7 @@ protected function getTime($timestamp): string
327342

328343
/**
329344
* Sets a value indicating whether this log target is enabled.
345+
*
330346
* @param bool|callable $value a boolean value or a callable to obtain the value from.
331347
*
332348
* A callable may be used to determine whether the log target should be enabled in a dynamic way.
@@ -338,6 +354,7 @@ protected function getTime($timestamp): string
338354
* return !Yii::getApp()->user->isGuest;
339355
* }
340356
* ```
357+
*
341358
* @return $this
342359
*/
343360
public function setEnabled($value): self
@@ -369,6 +386,7 @@ public function disable(): self
369386

370387
/**
371388
* Check whether the log target is enabled.
389+
*
372390
* @return bool A value indicating whether this log target is enabled.
373391
*/
374392
public function isEnabled(): bool

0 commit comments

Comments
 (0)