| Conditions | 9 |
| Paths | 4374 |
| Total Lines | 90 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 50 | public function testSandboxGloballySet() |
||
| 51 | { |
||
| 52 | $twig = $this->getEnvironment(false, array(), self::$templates); |
||
| 53 | $this->assertEquals('FOO', $twig->loadTemplate('1_basic')->render(self::$params), 'Sandbox does nothing if it is disabled globally'); |
||
| 54 | |||
| 55 | $twig = $this->getEnvironment(true, array(), self::$templates); |
||
| 56 | try { |
||
| 57 | $twig->loadTemplate('1_basic1')->render(self::$params); |
||
| 58 | $this->fail('Sandbox throws a SecurityError exception if an unallowed method is called'); |
||
| 59 | } catch (Twig_Sandbox_SecurityError $e) { |
||
|
|
|||
| 60 | } |
||
| 61 | |||
| 62 | $twig = $this->getEnvironment(true, array(), self::$templates); |
||
| 63 | try { |
||
| 64 | $twig->loadTemplate('1_basic2')->render(self::$params); |
||
| 65 | $this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called'); |
||
| 66 | } catch (Twig_Sandbox_SecurityError $e) { |
||
| 67 | } |
||
| 68 | |||
| 69 | $twig = $this->getEnvironment(true, array(), self::$templates); |
||
| 70 | try { |
||
| 71 | $twig->loadTemplate('1_basic3')->render(self::$params); |
||
| 72 | $this->fail('Sandbox throws a SecurityError exception if an unallowed tag is used in the template'); |
||
| 73 | } catch (Twig_Sandbox_SecurityError $e) { |
||
| 74 | } |
||
| 75 | |||
| 76 | $twig = $this->getEnvironment(true, array(), self::$templates); |
||
| 77 | try { |
||
| 78 | $twig->loadTemplate('1_basic4')->render(self::$params); |
||
| 79 | $this->fail('Sandbox throws a SecurityError exception if an unallowed property is called in the template'); |
||
| 80 | } catch (Twig_Sandbox_SecurityError $e) { |
||
| 81 | } |
||
| 82 | |||
| 83 | $twig = $this->getEnvironment(true, array(), self::$templates); |
||
| 84 | try { |
||
| 85 | $twig->loadTemplate('1_basic5')->render(self::$params); |
||
| 86 | $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); |
||
| 87 | } catch (Twig_Sandbox_SecurityError $e) { |
||
| 88 | } |
||
| 89 | |||
| 90 | $twig = $this->getEnvironment(true, array(), self::$templates); |
||
| 91 | try { |
||
| 92 | $twig->loadTemplate('1_basic6')->render(self::$params); |
||
| 93 | $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); |
||
| 94 | } catch (Twig_Sandbox_SecurityError $e) { |
||
| 95 | } |
||
| 96 | |||
| 97 | $twig = $this->getEnvironment(true, array(), self::$templates); |
||
| 98 | try { |
||
| 99 | $twig->loadTemplate('1_basic7')->render(self::$params); |
||
| 100 | $this->fail('Sandbox throws a SecurityError exception if an unallowed function is called in the template'); |
||
| 101 | } catch (Twig_Sandbox_SecurityError $e) { |
||
| 102 | } |
||
| 103 | |||
| 104 | $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array('FooObject' => 'foo')); |
||
| 105 | FooObject::reset(); |
||
| 106 | $this->assertEquals('foo', $twig->loadTemplate('1_basic1')->render(self::$params), 'Sandbox allow some methods'); |
||
| 107 | $this->assertEquals(1, FooObject::$called['foo'], 'Sandbox only calls method once'); |
||
| 108 | |||
| 109 | $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array('FooObject' => '__toString')); |
||
| 110 | FooObject::reset(); |
||
| 111 | $this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allow some methods'); |
||
| 112 | $this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once'); |
||
| 113 | |||
| 114 | $twig = $this->getEnvironment(false, array(), self::$templates); |
||
| 115 | FooObject::reset(); |
||
| 116 | $this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allows __toString when sandbox disabled'); |
||
| 117 | $this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once'); |
||
| 118 | |||
| 119 | $twig = $this->getEnvironment(true, array(), self::$templates, array(), array('upper')); |
||
| 120 | $this->assertEquals('FABIEN', $twig->loadTemplate('1_basic2')->render(self::$params), 'Sandbox allow some filters'); |
||
| 121 | |||
| 122 | $twig = $this->getEnvironment(true, array(), self::$templates, array('if')); |
||
| 123 | $this->assertEquals('foo', $twig->loadTemplate('1_basic3')->render(self::$params), 'Sandbox allow some tags'); |
||
| 124 | |||
| 125 | $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array(), array('FooObject' => 'bar')); |
||
| 126 | $this->assertEquals('bar', $twig->loadTemplate('1_basic4')->render(self::$params), 'Sandbox allow some properties'); |
||
| 127 | |||
| 128 | $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array(), array(), array('cycle')); |
||
| 129 | $this->assertEquals('bar', $twig->loadTemplate('1_basic7')->render(self::$params), 'Sandbox allow some functions'); |
||
| 130 | |||
| 131 | foreach (array('getfoobar', 'getFoobar', 'getFooBar') as $name) { |
||
| 132 | $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array('FooObject' => $name)); |
||
| 133 | FooObject::reset(); |
||
| 134 | $this->assertEquals('foobarfoobar', $twig->loadTemplate('1_basic8')->render(self::$params), 'Sandbox allow methods in a case-insensitive way'); |
||
| 135 | $this->assertEquals(2, FooObject::$called['getFooBar'], 'Sandbox only calls method once'); |
||
| 136 | |||
| 137 | $this->assertEquals('foobarfoobar', $twig->loadTemplate('1_basic9')->render(self::$params), 'Sandbox allow methods via shortcut names (ie. without get/set)'); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 221 |