Skip to content

Commit

Permalink
Code generate: add variadic type test
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Kalashnikov committed Sep 7, 2017
1 parent 3896ae0 commit 415eb03
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,39 @@ class Interceptor extends \Magento\Framework\Interception\Code\Generator\Sample
/**
* {@inheritdoc}
*/
public function variadic(... $values)
public function firstVariadicParameter(... $variadicValue)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'variadic');
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'firstVariadicParameter');
if (!$pluginInfo) {
return parent::variadic(... $values);
return parent::firstVariadicParameter(... $variadicValue);
} else {
return $this->___callPlugins('variadic', func_get_args(), $pluginInfo);
return $this->___callPlugins('firstVariadicParameter', func_get_args(), $pluginInfo);
}
}

/**
* {@inheritdoc}
*/
public function secondVariadicParameter($value, ... $variadicValue)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'secondVariadicParameter');
if (!$pluginInfo) {
return parent::secondVariadicParameter($value, ... $variadicValue);
} else {
return $this->___callPlugins('secondVariadicParameter', func_get_args(), $pluginInfo);
}
}

/**
* {@inheritdoc}
*/
public function byRefVariadic(&... $variadicValue)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'byRefVariadic');
if (!$pluginInfo) {
return parent::byRefVariadic(... $variadicValue);
} else {
return $this->___callPlugins('byRefVariadic', func_get_args(), $pluginInfo);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class Sample
{
private $attribute;
private $variadicAttribute;

public function getValue()
{
Expand All @@ -23,8 +24,19 @@ public function & getReference()
{
}

public function variadic(... $values)
public function firstVariadicParameter(...$variadicValue)
{
$this->attribute = array_shift($values);
$this->variadicAttribute = $variadicValue;
}

public function secondVariadicParameter($value, ...$variadicValue)
{
$this->attribute = $value;
$this->variadicAttribute = $variadicValue;
}

public function byRefVariadic(& ...$variadicValue)
{
$this->variadicAttribute = $variadicValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,43 @@ class Interceptor extends \Magento\Framework\Interception\Code\Generator\TSample
return $this->___callPlugins('setValue', func_get_args(), $pluginInfo);
}
}

/**
* {@inheritdoc}
*/
public function typeHintedFirstVariadicParameter(string ... $variadicValue)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'typeHintedFirstVariadicParameter');
if (!$pluginInfo) {
return parent::typeHintedFirstVariadicParameter(... $variadicValue);
} else {
return $this->___callPlugins('typeHintedFirstVariadicParameter', func_get_args(), $pluginInfo);
}
}

/**
* {@inheritdoc}
*/
public function typeHintedSecondVariadicParameter(string $value, string ... $variadicValue)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'typeHintedSecondVariadicParameter');
if (!$pluginInfo) {
return parent::typeHintedSecondVariadicParameter($value, ... $variadicValue);
} else {
return $this->___callPlugins('typeHintedSecondVariadicParameter', func_get_args(), $pluginInfo);
}
}

/**
* {@inheritdoc}
*/
public function byRefTypeHintedVariadic(string &... $variadicValue)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'byRefTypeHintedVariadic');
if (!$pluginInfo) {
return parent::byRefTypeHintedVariadic(... $variadicValue);
} else {
return $this->___callPlugins('byRefTypeHintedVariadic', func_get_args(), $pluginInfo);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class TSample
{
private $value;
private $variadicValue;

public function getValue() : string
{
Expand All @@ -18,4 +19,20 @@ public function setValue(string $value)
{
$this->value = $value;
}

public function typeHintedFirstVariadicParameter(string ...$variadicValue)
{
$this->variadicValue = $variadicValue;
}

public function typeHintedSecondVariadicParameter(string $value, string ...$variadicValue)
{
$this->value = $value;
$this->variadicValue = $variadicValue;
}

public function byRefTypeHintedVariadic(string & ...$variadicValue)
{
$this->variadicValue = $variadicValue;
}
}

0 comments on commit 415eb03

Please sign in to comment.