FunctionWrapper   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 69.57%

Importance

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

5 Methods

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