Skip to content

Commit 3f19d7d

Browse files
Consistently throw exceptions on a single line
1 parent 1ce7483 commit 3f19d7d

File tree

1 file changed

+12
-59
lines changed

1 file changed

+12
-59
lines changed

OptionsResolver.php

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,7 @@ public function setNormalizer($option, \Closure $normalizer)
388388
}
389389

390390
if (!isset($this->defined[$option])) {
391-
throw new UndefinedOptionsException(sprintf(
392-
'The option "%s" does not exist. Defined options are: "%s".',
393-
$option,
394-
implode('", "', array_keys($this->defined))
395-
));
391+
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
396392
}
397393

398394
$this->normalizers[$option] = $normalizer;
@@ -466,11 +462,7 @@ public function setAllowedValues($option, $allowedValues = null)
466462
}
467463

468464
if (!isset($this->defined[$option])) {
469-
throw new UndefinedOptionsException(sprintf(
470-
'The option "%s" does not exist. Defined options are: "%s".',
471-
$option,
472-
implode('", "', array_keys($this->defined))
473-
));
465+
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
474466
}
475467

476468
$this->allowedValues[$option] = \is_array($allowedValues) ? $allowedValues : array($allowedValues);
@@ -522,11 +514,7 @@ public function addAllowedValues($option, $allowedValues = null)
522514
}
523515

524516
if (!isset($this->defined[$option])) {
525-
throw new UndefinedOptionsException(sprintf(
526-
'The option "%s" does not exist. Defined options are: "%s".',
527-
$option,
528-
implode('", "', array_keys($this->defined))
529-
));
517+
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
530518
}
531519

532520
if (!\is_array($allowedValues)) {
@@ -578,11 +566,7 @@ public function setAllowedTypes($option, $allowedTypes = null)
578566
}
579567

580568
if (!isset($this->defined[$option])) {
581-
throw new UndefinedOptionsException(sprintf(
582-
'The option "%s" does not exist. Defined options are: "%s".',
583-
$option,
584-
implode('", "', array_keys($this->defined))
585-
));
569+
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
586570
}
587571

588572
$this->allowedTypes[$option] = (array) $allowedTypes;
@@ -628,11 +612,7 @@ public function addAllowedTypes($option, $allowedTypes = null)
628612
}
629613

630614
if (!isset($this->defined[$option])) {
631-
throw new UndefinedOptionsException(sprintf(
632-
'The option "%s" does not exist. Defined options are: "%s".',
633-
$option,
634-
implode('", "', array_keys($this->defined))
635-
));
615+
throw new UndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
636616
}
637617

638618
if (!isset($this->allowedTypes[$option])) {
@@ -737,11 +717,7 @@ public function resolve(array $options = array())
737717
ksort($clone->defined);
738718
ksort($diff);
739719

740-
throw new UndefinedOptionsException(sprintf(
741-
(\count($diff) > 1 ? 'The options "%s" do not exist.' : 'The option "%s" does not exist.').' Defined options are: "%s".',
742-
implode('", "', array_keys($diff)),
743-
implode('", "', array_keys($clone->defined))
744-
));
720+
throw new UndefinedOptionsException(sprintf((\count($diff) > 1 ? 'The options "%s" do not exist.' : 'The option "%s" does not exist.').' Defined options are: "%s".', implode('", "', array_keys($diff)), implode('", "', array_keys($clone->defined))));
745721
}
746722

747723
// Override options set by the user
@@ -756,10 +732,7 @@ public function resolve(array $options = array())
756732
if (\count($diff) > 0) {
757733
ksort($diff);
758734

759-
throw new MissingOptionsException(sprintf(
760-
\count($diff) > 1 ? 'The required options "%s" are missing.' : 'The required option "%s" is missing.',
761-
implode('", "', array_keys($diff))
762-
));
735+
throw new MissingOptionsException(sprintf(\count($diff) > 1 ? 'The required options "%s" are missing.' : 'The required option "%s" is missing.', implode('", "', array_keys($diff))));
763736
}
764737

765738
// Lock the container
@@ -803,17 +776,10 @@ public function offsetGet($option)
803776
// Check whether the option is set at all
804777
if (!array_key_exists($option, $this->defaults)) {
805778
if (!isset($this->defined[$option])) {
806-
throw new NoSuchOptionException(sprintf(
807-
'The option "%s" does not exist. Defined options are: "%s".',
808-
$option,
809-
implode('", "', array_keys($this->defined))
810-
));
779+
throw new NoSuchOptionException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
811780
}
812781

813-
throw new NoSuchOptionException(sprintf(
814-
'The optional option "%s" has no value set. You should make sure it is set with "isset" before reading it.',
815-
$option
816-
));
782+
throw new NoSuchOptionException(sprintf('The optional option "%s" has no value set. You should make sure it is set with "isset" before reading it.', $option));
817783
}
818784

819785
$value = $this->defaults[$option];
@@ -823,10 +789,7 @@ public function offsetGet($option)
823789
// If the closure is already being called, we have a cyclic
824790
// dependency
825791
if (isset($this->calling[$option])) {
826-
throw new OptionDefinitionException(sprintf(
827-
'The options "%s" have a cyclic dependency.',
828-
implode('", "', array_keys($this->calling))
829-
));
792+
throw new OptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', implode('", "', array_keys($this->calling))));
830793
}
831794

832795
// The following section must be protected from cyclic
@@ -872,14 +835,7 @@ public function offsetGet($option)
872835
}
873836

874837
if (!$valid) {
875-
throw new InvalidOptionsException(sprintf(
876-
'The option "%s" with value %s is expected to be of type '.
877-
'"%s", but is of type "%s".',
878-
$option,
879-
$this->formatValue($value),
880-
implode('" or "', $this->allowedTypes[$option]),
881-
$this->formatTypeOf($value)
882-
));
838+
throw new InvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but is of type "%s".', $option, $this->formatValue($value), implode('" or "', $this->allowedTypes[$option]), $this->formatTypeOf($value)));
883839
}
884840
}
885841

@@ -928,10 +884,7 @@ public function offsetGet($option)
928884
// If the closure is already being called, we have a cyclic
929885
// dependency
930886
if (isset($this->calling[$option])) {
931-
throw new OptionDefinitionException(sprintf(
932-
'The options "%s" have a cyclic dependency.',
933-
implode('", "', array_keys($this->calling))
934-
));
887+
throw new OptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', implode('", "', array_keys($this->calling))));
935888
}
936889

937890
$normalizer = $this->normalizers[$option];

0 commit comments

Comments
 (0)