Passed
Push — master ( 151185...42f330 )
by P.R.
04:09
created

FunctionWrapper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 69.57%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 70
ccs 16
cts 23
cp 0.6957
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A writeResultHandler() 0 16 2
A writeRoutineFunctionLobFetchData() 0 4 1
A writeRoutineFunctionLobReturnData() 0 9 2
A getReturnTypeDeclaration() 0 7 2
A getDocBlockReturnType() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SetBased\Stratum\MySql\Wrapper;
5
6
use SetBased\Stratum\Middle\Exception\ResultException;
7
use SetBased\Stratum\MySql\Exception\MySqlDataLayerException;
8
use SetBased\Stratum\MySql\Helper\DataTypeHelper;
9
10
/**
11
 * Class for generating a wrapper method for a stored function.
12
 */
13
class FunctionWrapper extends Wrapper
14
{
15
  //--------------------------------------------------------------------------------------------------------------------
16
  /**
17
   * @inheritdoc
18
   */
19 1
  protected function getDocBlockReturnType(): string
20
  {
21 1
    return $this->routine['return'];
22
  }
23
24
  //--------------------------------------------------------------------------------------------------------------------
25
  /**
26
   * @inheritdoc
27
   */
28 1
  protected function getReturnTypeDeclaration(): string
29
  {
30 1
    $type = DataTypeHelper::phpTypeHintingToPhpTypeDeclaration($this->getDocBlockReturnType());
31
32 1
    if ($type==='') return '';
33
34 1
    return ': '.$type;
35
  }
36
37
  //--------------------------------------------------------------------------------------------------------------------
38
  /**
39
   * @inheritdoc
40
   */
41 1
  protected function writeResultHandler(): void
42
  {
43 1
    $this->throws(MySqlDataLayerException::class);
44 1
    $this->throws(ResultException::class);
45
46 1
    if ($this->routine['return']=='bool')
47
    {
48 1
      $this->codeStore->append(sprintf("return !empty(\$this->executeSingleton0('select %s(%s)'));",
49 1
                                       $this->routine['routine_name'],
50 1
                                       $this->getRoutineArgs()));
51
    }
52
    else
53
    {
54 1
      $this->codeStore->append(sprintf("return \$this->executeSingleton0('select %s(%s)');",
55 1
                                       $this->routine['routine_name'],
56 1
                                       $this->getRoutineArgs()));
57
    }
58
  }
59
60
  //--------------------------------------------------------------------------------------------------------------------
61
  /**
62
   * @inheritdoc
63
   */
64
  protected function writeRoutineFunctionLobFetchData(): void
65
  {
66
    $this->codeStore->append('$ret = $this->mysqli->affected_rows;');
67
    $this->codeStore->append('');
68
  }
69
70
  //--------------------------------------------------------------------------------------------------------------------
71
  /**
72
   * @inheritdoc
73
   */
74
  protected function writeRoutineFunctionLobReturnData(): void
75
  {
76
    if ($this->routine['return']=='bool')
77
    {
78
      $this->codeStore->append('return !empty($ret);');
79
    }
80
    else
81
    {
82
      $this->codeStore->append('return $ret;');
83
    }
84
  }
85
86
  //--------------------------------------------------------------------------------------------------------------------
87
}
88
89
//----------------------------------------------------------------------------------------------------------------------
90