Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9813888

Browse files
ReenExefabpot
authored andcommitted
undefined offset fix (#19406)
1 parent 37cd583 commit 9813888

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ public static function getStyleDefinition($name)
101101
self::$styles = self::initStyles();
102102
}
103103

104-
if (!self::$styles[$name]) {
105-
throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
104+
if (isset(self::$styles[$name])) {
105+
return self::$styles[$name];
106106
}
107107

108-
return self::$styles[$name];
108+
throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
109109
}
110110

111111
/**
@@ -117,13 +117,7 @@ public static function getStyleDefinition($name)
117117
*/
118118
public function setStyle($name)
119119
{
120-
if ($name instanceof TableStyle) {
121-
$this->style = $name;
122-
} elseif (isset(self::$styles[$name])) {
123-
$this->style = self::$styles[$name];
124-
} else {
125-
throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
126-
}
120+
$this->style = $this->resolveStyle($name);
127121

128122
return $this;
129123
}
@@ -611,4 +605,17 @@ private static function initStyles()
611605
'symfony-style-guide' => $styleGuide,
612606
);
613607
}
608+
609+
private function resolveStyle($name)
610+
{
611+
if ($name instanceof TableStyle) {
612+
return $name;
613+
}
614+
615+
if (isset(self::$styles[$name])) {
616+
return self::$styles[$name];
617+
}
618+
619+
throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
620+
}
614621
}

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,25 @@ public function testRowSeparator()
577577
$this->assertEquals($table, $table->addRow(new TableSeparator()), 'fluent interface on addRow() with a single TableSeparator() works');
578578
}
579579

580+
/**
581+
* @expectedException \InvalidArgumentException
582+
* @expectedExceptionMessage Style "absent" is not defined.
583+
*/
584+
public function testIsNotDefinedStyleException()
585+
{
586+
$table = new Table($this->getOutputStream());
587+
$table->setStyle('absent');
588+
}
589+
590+
/**
591+
* @expectedException \InvalidArgumentException
592+
* @expectedExceptionMessage Style "absent" is not defined.
593+
*/
594+
public function testGetStyleDefinition()
595+
{
596+
Table::getStyleDefinition('absent');
597+
}
598+
580599
protected function getOutputStream()
581600
{
582601
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, false);

0 commit comments

Comments
 (0)