Completed
Push — master ( e25cba...17602b )
by Chris
01:54
created

Run::modelTypeId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
/*
3
This project is Licenced under The MIT License (MIT)
4
5
Copyright (c) 2014 Christopher Seufert
6
7
Permission is hereby granted, free of charge, to any person obtaining a copy
8
of this software and associated documentation files (the "Software"), to deal
9
in the Software without restriction, including without limitation the rights
10
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
copies of the Software, and to permit persons to whom the Software is
12
furnished to do so, subject to the following conditions:
13
14
The above copyright notice and this permission notice shall be included in
15
all copies or substantial portions of the Software.
16
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
THE SOFTWARE.
24
25
 */
26
namespace Seufert\Hamle;
27
28
use Seufert\Hamle\Exception\RunTime;
29
use Seufert\Hamle\Model;
30
31
/**
32
 * HAMLE Runtime
33
 *
34
 * @author Chris Seufert <[email protected]>
35
 */
36
class Run {
37
  /**
38
   * @var Hamle Current HAMLE instance
39
   */
40
  static protected $hamle;
41
  static protected $hamleList = array();
42
43
  /**
44
   * Add a hamle instance to the stack
45
   * @param Hamle $hamle Hamle Instance
46
   */
47
  static function addInstance(Hamle $hamle) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
48
    self::$hamleList[] = $hamle;
49
    self::$hamle = $hamle;
50
  }
51
52
  /**
53
   * Remove hamle Instance from the stack
54
   */
55
  static function popInstance() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56
    array_pop(self::$hamleList);
57
    if (self::$hamleList)
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$hamleList of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
58
      self::$hamle = self::$hamleList[count(self::$hamleList) - 1];
59
    else
60
      self::$hamle = NULL;
61
  }
62
63
  /**
64
   * Execute a hamle String Filter
65
   * @param string $name Name of Filter
66
   * @param string $data Data to pass to filter
67
   * @return string Fitlered data
68
   */
69
  static function filter($name, $data) {
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
70
    return strrev($data);
71
  }
72
73
  /**
74
   * Helper for hamle |include command
75
   * @param string $path Path to file to include
76
   * @return string HTML Code
77
   */
78
  static function includeFile($path) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
79
    return self::$hamle->load($path)->output();
80
  }
81
82
  /**
83
   * @param $fragment Name of fragment
84
   * @internal Only for use in template system
85
   * @return string String to output where |include #fragment was called
86
   */
87
  static function includeFragment($fragment) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
88
    return self::$hamle->setup->getFragment(self::$hamle, substr($fragment, 1));
89
  }
90
91
  /**
92
   * Called from template by $() to find a specific model
93
   * @param array[] $typeTags array of tags with types as key eg ['page'=>[]] or ['product'=>['featured]]
94
   * @param array $sort
95
   * @param int $limit Results Limit
96
   * @param int $offset Offset Results by
97
   * @internal param string $sortBy Field name to sort by
98
   * @return Model
99
   */
100
  static function modelTypeTags($typeTags, $sort = [], $limit = 0, $offset = 0) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
101
    return self::$hamle->setup->getModelTypeTags($typeTags,
102
        $sort, $limit, $offset);
103
  }
104
105
  /**
106
   * Called from template by $() to find a specific model
107
   * @param string $id id to search for
108
   * @param array $sort
109
   * @param int $limit Limit of results
110
   * @param int $offset Results Offset
111
   * @throws RunTime
112
   * @return Model
113
   */
114
  static function modelId($id, $sort = [], $limit = 0, $offset = 0) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
115
    $o = self::$hamle->setup->getModelDefault($id, $sort, $limit, $offset);
116
    if (!$o instanceOf Model) throw new RunTime("Application must return instance of hamleModel");
117
    return $o;
118
  }
119
120
  /**
121
   * Called from template by $() to find a specific model
122
   * @param array[] $typeId Array of types mapped to ids [type1=>[1],type2=>[2]]
123
   * @param int $sortDir Sort Direction defined by hamle::SORT_*
0 ignored issues
show
Bug introduced by
There is no parameter named $sortDir. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
124
   * @param string $sortField Field name to sort by
0 ignored issues
show
Bug introduced by
There is no parameter named $sortField. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
125
   * @param int $limit Results Limit
126
   * @param int $offset Results Offset
127
   * @internal param string $type type to filter by
128
   * @internal param string $id id to search for
129
   * @return Model
130
   */
131
  static function modelTypeId($typeId, $sort = [], $limit = 0, $offset = 0) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
132
    return self::$hamle->setup->getModelTypeId($typeId, $sort, $limit, $offset);
133
  }
134
135
136
}
137