Skip to content

Commit f642a9c

Browse files
committed
Prefix all sprintf() calls
1 parent 6e7c3ad commit f642a9c

21 files changed

+91
-91
lines changed

Attribute/BuildEventNameTrait.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ private static function buildEventName(string $keyword, string $argument, ?strin
2424
{
2525
if (null === $workflow) {
2626
if (null !== $node) {
27-
throw new LogicException(sprintf('The "%s" argument of "%s" cannot be used without a "workflow" argument.', $argument, self::class));
27+
throw new LogicException(\sprintf('The "%s" argument of "%s" cannot be used without a "workflow" argument.', $argument, self::class));
2828
}
2929

30-
return sprintf('workflow.%s', $keyword);
30+
return \sprintf('workflow.%s', $keyword);
3131
}
3232

3333
if (null === $node) {
34-
return sprintf('workflow.%s.%s', $workflow, $keyword);
34+
return \sprintf('workflow.%s.%s', $workflow, $keyword);
3535
}
3636

37-
return sprintf('workflow.%s.%s.%s', $workflow, $keyword, $node);
37+
return \sprintf('workflow.%s.%s.%s', $workflow, $keyword, $node);
3838
}
3939
}

DataCollector/WorkflowDataCollector.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ protected function getCasters(): array
9494
...parent::getCasters(),
9595
TransitionBlocker::class => function ($v, array $a, Stub $s, $isNested) {
9696
unset(
97-
$a[sprintf(Caster::PATTERN_PRIVATE, $v::class, 'code')],
98-
$a[sprintf(Caster::PATTERN_PRIVATE, $v::class, 'parameters')],
97+
$a[\sprintf(Caster::PATTERN_PRIVATE, $v::class, 'code')],
98+
$a[\sprintf(Caster::PATTERN_PRIVATE, $v::class, 'parameters')],
9999
);
100100

101101
$s->cut += 2;
@@ -129,9 +129,9 @@ private function getEventListeners(WorkflowInterface $workflow): array
129129
'entered',
130130
];
131131
foreach ($subEventNames as $subEventName) {
132-
$eventNames[] = sprintf('workflow.%s', $subEventName);
133-
$eventNames[] = sprintf('workflow.%s.%s', $workflow->getName(), $subEventName);
134-
$eventNames[] = sprintf('workflow.%s.%s.%s', $workflow->getName(), $subEventName, $place);
132+
$eventNames[] = \sprintf('workflow.%s', $subEventName);
133+
$eventNames[] = \sprintf('workflow.%s.%s', $workflow->getName(), $subEventName);
134+
$eventNames[] = \sprintf('workflow.%s.%s.%s', $workflow->getName(), $subEventName, $place);
135135
}
136136
foreach ($eventNames as $eventName) {
137137
foreach ($this->eventDispatcher->getListeners($eventName) as $listener) {
@@ -151,9 +151,9 @@ private function getEventListeners(WorkflowInterface $workflow): array
151151
'announce',
152152
];
153153
foreach ($subEventNames as $subEventName) {
154-
$eventNames[] = sprintf('workflow.%s', $subEventName);
155-
$eventNames[] = sprintf('workflow.%s.%s', $workflow->getName(), $subEventName);
156-
$eventNames[] = sprintf('workflow.%s.%s.%s', $workflow->getName(), $subEventName, $transition->getName());
154+
$eventNames[] = \sprintf('workflow.%s', $subEventName);
155+
$eventNames[] = \sprintf('workflow.%s.%s', $workflow->getName(), $subEventName);
156+
$eventNames[] = \sprintf('workflow.%s.%s.%s', $workflow->getName(), $subEventName, $transition->getName());
157157
}
158158
foreach ($eventNames as $eventName) {
159159
foreach ($this->eventDispatcher->getListeners($eventName) as $listener) {

Definition.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function setInitialPlaces(string|array|null $places): void
8686

8787
foreach ($places as $place) {
8888
if (!isset($this->places[$place])) {
89-
throw new LogicException(sprintf('Place "%s" cannot be the initial place as it does not exist.', $place));
89+
throw new LogicException(\sprintf('Place "%s" cannot be the initial place as it does not exist.', $place));
9090
}
9191
}
9292

DependencyInjection/WorkflowGuardListenerPass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function process(ContainerBuilder $container): void
3838

3939
foreach ($servicesNeeded as $service) {
4040
if (!$container->has($service)) {
41-
throw new LogicException(sprintf('The "%s" service is needed to be able to use the workflow guard listener.', $service));
41+
throw new LogicException(\sprintf('The "%s" service is needed to be able to use the workflow guard listener.', $service));
4242
}
4343
}
4444
}

Dumper/GraphvizDumper.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ protected function addPlaces(array $places, float $withMetadata): string
154154
}
155155

156156
if ($withMetadata) {
157-
$escapedLabel = sprintf('<<B>%s</B>%s>', $this->escape($placeName), $this->addMetadata($place['attributes']['metadata']));
157+
$escapedLabel = \sprintf('<<B>%s</B>%s>', $this->escape($placeName), $this->addMetadata($place['attributes']['metadata']));
158158
// Don't include metadata in default attributes used to format the place
159159
unset($place['attributes']['metadata']);
160160
} else {
161-
$escapedLabel = sprintf('"%s"', $this->escape($placeName));
161+
$escapedLabel = \sprintf('"%s"', $this->escape($placeName));
162162
}
163163

164-
$code .= sprintf(" place_%s [label=%s, shape=circle%s];\n", $this->dotize($id), $escapedLabel, $this->addAttributes($place['attributes']));
164+
$code .= \sprintf(" place_%s [label=%s, shape=circle%s];\n", $this->dotize($id), $escapedLabel, $this->addAttributes($place['attributes']));
165165
}
166166

167167
return $code;
@@ -176,12 +176,12 @@ protected function addTransitions(array $transitions, bool $withMetadata): strin
176176

177177
foreach ($transitions as $i => $place) {
178178
if ($withMetadata) {
179-
$escapedLabel = sprintf('<<B>%s</B>%s>', $this->escape($place['name']), $this->addMetadata($place['metadata']));
179+
$escapedLabel = \sprintf('<<B>%s</B>%s>', $this->escape($place['name']), $this->addMetadata($place['metadata']));
180180
} else {
181181
$escapedLabel = '"'.$this->escape($place['name']).'"';
182182
}
183183

184-
$code .= sprintf(" transition_%s [label=%s,%s];\n", $this->dotize($i), $escapedLabel, $this->addAttributes($place['attributes']));
184+
$code .= \sprintf(" transition_%s [label=%s,%s];\n", $this->dotize($i), $escapedLabel, $this->addAttributes($place['attributes']));
185185
}
186186

187187
return $code;
@@ -229,12 +229,12 @@ protected function addEdges(array $edges): string
229229

230230
foreach ($edges as $edge) {
231231
if ('from' === $edge['direction']) {
232-
$code .= sprintf(" place_%s -> transition_%s [style=\"solid\"];\n",
232+
$code .= \sprintf(" place_%s -> transition_%s [style=\"solid\"];\n",
233233
$this->dotize($edge['from']),
234234
$this->dotize($edge['transition_number'])
235235
);
236236
} else {
237-
$code .= sprintf(" transition_%s -> place_%s [style=\"solid\"];\n",
237+
$code .= \sprintf(" transition_%s -> place_%s [style=\"solid\"];\n",
238238
$this->dotize($edge['transition_number']),
239239
$this->dotize($edge['to'])
240240
);
@@ -249,9 +249,9 @@ protected function addEdges(array $edges): string
249249
*/
250250
protected function startDot(array $options, string $label): string
251251
{
252-
return sprintf("digraph workflow {\n %s%s\n node [%s];\n edge [%s];\n\n",
252+
return \sprintf("digraph workflow {\n %s%s\n node [%s];\n edge [%s];\n\n",
253253
$this->addOptions($options['graph']),
254-
'""' !== $label && '<>' !== $label ? sprintf(' label=%s', $label) : '',
254+
'""' !== $label && '<>' !== $label ? \sprintf(' label=%s', $label) : '',
255255
$this->addOptions($options['node']),
256256
$this->addOptions($options['edge'])
257257
);
@@ -289,7 +289,7 @@ protected function addAttributes(array $attributes): string
289289
$code = [];
290290

291291
foreach ($attributes as $k => $v) {
292-
$code[] = sprintf('%s="%s"', $k, $this->escape($v));
292+
$code[] = \sprintf('%s="%s"', $k, $this->escape($v));
293293
}
294294

295295
return $code ? ' '.implode(' ', $code) : '';
@@ -309,25 +309,25 @@ protected function formatLabel(Definition $definition, string $withMetadata, arr
309309

310310
if (!$withMetadata) {
311311
// Only currentLabel to handle. If null, will be translated to empty string
312-
return sprintf('"%s"', $this->escape($currentLabel));
312+
return \sprintf('"%s"', $this->escape($currentLabel));
313313
}
314314
$workflowMetadata = $definition->getMetadataStore()->getWorkflowMetadata();
315315

316316
if ('' === $currentLabel) {
317317
// Only metadata to handle
318-
return sprintf('<%s>', $this->addMetadata($workflowMetadata, false));
318+
return \sprintf('<%s>', $this->addMetadata($workflowMetadata, false));
319319
}
320320

321321
// currentLabel and metadata to handle
322-
return sprintf('<<B>%s</B>%s>', $this->escape($currentLabel), $this->addMetadata($workflowMetadata));
322+
return \sprintf('<<B>%s</B>%s>', $this->escape($currentLabel), $this->addMetadata($workflowMetadata));
323323
}
324324

325325
private function addOptions(array $options): string
326326
{
327327
$code = [];
328328

329329
foreach ($options as $k => $v) {
330-
$code[] = sprintf('%s="%s"', $k, $v);
330+
$code[] = \sprintf('%s="%s"', $k, $v);
331331
}
332332

333333
return implode(' ', $code);
@@ -344,10 +344,10 @@ private function addMetadata(array $metadata, bool $lineBreakFirstIfNotEmpty = t
344344

345345
foreach ($metadata as $key => $value) {
346346
if ($skipSeparator) {
347-
$code[] = sprintf('%s: %s', $this->escape($key), $this->escape($value));
347+
$code[] = \sprintf('%s: %s', $this->escape($key), $this->escape($value));
348348
$skipSeparator = false;
349349
} else {
350-
$code[] = sprintf('%s%s: %s', '<BR/>', $this->escape($key), $this->escape($value));
350+
$code[] = \sprintf('%s%s: %s', '<BR/>', $this->escape($key), $this->escape($value));
351351
}
352352
}
353353

Dumper/MermaidDumper.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private function preparePlace(int $placeId, string $placeName, array $meta, bool
138138

139139
$placeNodeName = 'place'.$placeId;
140140
$placeNodeFormat = '%s'.$labelShape;
141-
$placeNode = sprintf($placeNodeFormat, $placeNodeName, $placeLabel);
141+
$placeNode = \sprintf($placeNodeFormat, $placeNodeName, $placeLabel);
142142

143143
$placeStyle = $this->styleNode($meta, $placeNodeName, $hasMarking);
144144

@@ -150,7 +150,7 @@ private function styleNode(array $meta, string $nodeName, bool $hasMarking = fal
150150
$nodeStyles = [];
151151

152152
if (\array_key_exists('bg_color', $meta)) {
153-
$nodeStyles[] = sprintf(
153+
$nodeStyles[] = \sprintf(
154154
'fill:%s',
155155
$meta['bg_color']
156156
);
@@ -164,7 +164,7 @@ private function styleNode(array $meta, string $nodeName, bool $hasMarking = fal
164164
return '';
165165
}
166166

167-
return sprintf('style %s %s', $nodeName, implode(',', $nodeStyles));
167+
return \sprintf('style %s %s', $nodeName, implode(',', $nodeStyles));
168168
}
169169

170170
/**
@@ -175,26 +175,26 @@ private function escape(string $label): string
175175
{
176176
$label = str_replace('"', '#quot;', $label);
177177

178-
return sprintf('"%s"', $label);
178+
return \sprintf('"%s"', $label);
179179
}
180180

181181
public function validateDirection(string $direction): void
182182
{
183183
if (!\in_array($direction, self::VALID_DIRECTIONS, true)) {
184-
throw new InvalidArgumentException(sprintf('Direction "%s" is not valid, valid directions are: "%s".', $direction, implode(', ', self::VALID_DIRECTIONS)));
184+
throw new InvalidArgumentException(\sprintf('Direction "%s" is not valid, valid directions are: "%s".', $direction, implode(', ', self::VALID_DIRECTIONS)));
185185
}
186186
}
187187

188188
private function validateTransitionType(string $transitionType): void
189189
{
190190
if (!\in_array($transitionType, self::VALID_TRANSITION_TYPES, true)) {
191-
throw new InvalidArgumentException(sprintf('Transition type "%s" is not valid, valid types are: "%s".', $transitionType, implode(', ', self::VALID_TRANSITION_TYPES)));
191+
throw new InvalidArgumentException(\sprintf('Transition type "%s" is not valid, valid types are: "%s".', $transitionType, implode(', ', self::VALID_TRANSITION_TYPES)));
192192
}
193193
}
194194

195195
private function styleStateMachineTransition(string $from, string $to, string $transitionLabel, array $transitionMeta): array
196196
{
197-
$transitionOutput = [sprintf('%s-->|%s|%s', $from, str_replace("\n", ' ', $this->escape($transitionLabel)), $to)];
197+
$transitionOutput = [\sprintf('%s-->|%s|%s', $from, str_replace("\n", ' ', $this->escape($transitionLabel)), $to)];
198198

199199
$linkStyle = $this->styleLink($transitionMeta);
200200
if ('' !== $linkStyle) {
@@ -213,15 +213,15 @@ private function styleWorkflowTransition(string $from, string $to, int $transiti
213213
$transitionLabel = $this->escape($transitionLabel);
214214
$transitionNodeName = 'transition'.$transitionId;
215215

216-
$transitionOutput[] = sprintf('%s[%s]', $transitionNodeName, $transitionLabel);
216+
$transitionOutput[] = \sprintf('%s[%s]', $transitionNodeName, $transitionLabel);
217217

218218
$transitionNodeStyle = $this->styleNode($transitionMeta, $transitionNodeName);
219219
if ('' !== $transitionNodeStyle) {
220220
$transitionOutput[] = $transitionNodeStyle;
221221
}
222222

223223
$connectionStyle = '%s-->%s';
224-
$transitionOutput[] = sprintf($connectionStyle, $from, $transitionNodeName);
224+
$transitionOutput[] = \sprintf($connectionStyle, $from, $transitionNodeName);
225225

226226
$linkStyle = $this->styleLink($transitionMeta);
227227
if ('' !== $linkStyle) {
@@ -230,7 +230,7 @@ private function styleWorkflowTransition(string $from, string $to, int $transiti
230230

231231
++$this->linkCount;
232232

233-
$transitionOutput[] = sprintf($connectionStyle, $transitionNodeName, $to);
233+
$transitionOutput[] = \sprintf($connectionStyle, $transitionNodeName, $to);
234234

235235
$linkStyle = $this->styleLink($transitionMeta);
236236
if ('' !== $linkStyle) {
@@ -245,7 +245,7 @@ private function styleWorkflowTransition(string $from, string $to, int $transiti
245245
private function styleLink(array $transitionMeta): string
246246
{
247247
if (\array_key_exists('color', $transitionMeta)) {
248-
return sprintf('linkStyle %d stroke:%s', $this->linkCount, $transitionMeta['color']);
248+
return \sprintf('linkStyle %d stroke:%s', $this->linkCount, $transitionMeta['color']);
249249
}
250250

251251
return '';

Dumper/PlantUmlDumper.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ private function getTransitionEscapedWithStyle(MetadataStoreInterface $workflowM
226226
if (null !== $color) {
227227
// Close and open <font> before and after every '\n' string,
228228
// so that the style is applied properly on every line
229-
$to = str_replace('\n', sprintf('</font>\n<font color=%1$s>', $color), $to);
229+
$to = str_replace('\n', \sprintf('</font>\n<font color=%1$s>', $color), $to);
230230

231-
$to = sprintf(
231+
$to = \sprintf(
232232
'<font color=%1$s>%2$s</font>',
233233
$color,
234234
$to
@@ -245,7 +245,7 @@ private function getTransitionColor(string $color): string
245245
$color = '#'.$color;
246246
}
247247

248-
return sprintf('[%s]', $color);
248+
return \sprintf('[%s]', $color);
249249
}
250250

251251
private function getColorId(string $color): string

Dumper/StateMachineGraphvizDumper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function addEdges(array $edges): string
8989

9090
foreach ($edges as $id => $edges) {
9191
foreach ($edges as $edge) {
92-
$code .= sprintf(
92+
$code .= \sprintf(
9393
" place_%s -> place_%s [label=\"%s\" style=\"%s\"%s];\n",
9494
$this->dotize($id),
9595
$this->dotize($edge['to']),

Event/EventNameTrait.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ private static function computeName(?string $workflowName, ?string $transitionOr
4949
throw new \InvalidArgumentException('Missing workflow name.');
5050
}
5151

52-
return sprintf('workflow.%s', $eventName);
52+
return \sprintf('workflow.%s', $eventName);
5353
}
5454

5555
if (null === $transitionOrPlaceName) {
56-
return sprintf('workflow.%s.%s', $workflowName, $eventName);
56+
return \sprintf('workflow.%s.%s', $workflowName, $eventName);
5757
}
5858

59-
return sprintf('workflow.%s.%s.%s', $workflowName, $eventName, $transitionOrPlaceName);
59+
return \sprintf('workflow.%s.%s.%s', $workflowName, $eventName, $transitionOrPlaceName);
6060
}
6161
}

EventListener/AuditTrailListener.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ public function __construct(
2828
public function onLeave(Event $event): void
2929
{
3030
foreach ($event->getTransition()->getFroms() as $place) {
31-
$this->logger->info(sprintf('Leaving "%s" for subject of class "%s" in workflow "%s".', $place, $event->getSubject()::class, $event->getWorkflowName()));
31+
$this->logger->info(\sprintf('Leaving "%s" for subject of class "%s" in workflow "%s".', $place, $event->getSubject()::class, $event->getWorkflowName()));
3232
}
3333
}
3434

3535
public function onTransition(Event $event): void
3636
{
37-
$this->logger->info(sprintf('Transition "%s" for subject of class "%s" in workflow "%s".', $event->getTransition()->getName(), $event->getSubject()::class, $event->getWorkflowName()));
37+
$this->logger->info(\sprintf('Transition "%s" for subject of class "%s" in workflow "%s".', $event->getTransition()->getName(), $event->getSubject()::class, $event->getWorkflowName()));
3838
}
3939

4040
public function onEnter(Event $event): void
4141
{
4242
foreach ($event->getTransition()->getTos() as $place) {
43-
$this->logger->info(sprintf('Entering "%s" for subject of class "%s" in workflow "%s".', $place, $event->getSubject()::class, $event->getWorkflowName()));
43+
$this->logger->info(\sprintf('Entering "%s" for subject of class "%s" in workflow "%s".', $place, $event->getSubject()::class, $event->getWorkflowName()));
4444
}
4545
}
4646

EventListener/ExpressionLanguage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ protected function registerFunctions(): void
2626
{
2727
parent::registerFunctions();
2828

29-
$this->register('is_granted', fn ($attributes, $object = 'null') => sprintf('$auth_checker->isGranted(%s, %s)', $attributes, $object), fn (array $variables, $attributes, $object = null) => $variables['auth_checker']->isGranted($attributes, $object));
29+
$this->register('is_granted', fn ($attributes, $object = 'null') => \sprintf('$auth_checker->isGranted(%s, %s)', $attributes, $object), fn (array $variables, $attributes, $object = null) => $variables['auth_checker']->isGranted($attributes, $object));
3030

31-
$this->register('is_valid', fn ($object = 'null', $groups = 'null') => sprintf('0 === count($validator->validate(%s, null, %s))', $object, $groups), function (array $variables, $object = null, $groups = null) {
31+
$this->register('is_valid', fn ($object = 'null', $groups = 'null') => \sprintf('0 === count($validator->validate(%s, null, %s))', $object, $groups), function (array $variables, $object = null, $groups = null) {
3232
if (!$variables['validator'] instanceof ValidatorInterface) {
3333
throw new RuntimeException('"is_valid" cannot be used as the Validator component is not installed. Try running "composer require symfony/validator".');
3434
}

Exception/NotEnabledTransitionException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828
private TransitionBlockerList $transitionBlockerList,
2929
array $context = [],
3030
) {
31-
parent::__construct($subject, $transitionName, $workflow, sprintf('Transition "%s" is not enabled for workflow "%s".', $transitionName, $workflow->getName()), $context);
31+
parent::__construct($subject, $transitionName, $workflow, \sprintf('Transition "%s" is not enabled for workflow "%s".', $transitionName, $workflow->getName()), $context);
3232
}
3333

3434
public function getTransitionBlockerList(): TransitionBlockerList

0 commit comments

Comments
 (0)