TwigExtension::getFunctions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 21
rs 9.3142
cc 2
eloc 10
nc 2
nop 0
1
<?php
2
/*
3
 * This file is part of Yolk - Gamer Network's PHP Framework.
4
 *
5
 * Copyright (c) 2015 Gamer Network Ltd.
6
 *
7
 * Distributed under the MIT License, a copy of which is available in the
8
 * LICENSE file that was bundled with this package, or online at:
9
 * https://github.com/gamernetwork/yolk-support
10
 */
11
12
namespace yolk\support;
13
14
class TwigExtension extends \Twig_Extension {
15
16
	public function getName() {
17
		return 'Yolk Twig Extension';
18
	}
19
20
	public function getTests() {
21
		return [
22
			new \Twig_SimpleTest('numeric', function( $value ) {
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleTest has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
23
				return is_numeric($value);
24
			}),
25
			new \Twig_SimpleTest('integer', function( $value ) {
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleTest has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
26
				return is_numeric($value) && ($value == (int) $value);
27
			}),
28
			new \Twig_SimpleTest('string', function( $value ) {
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleTest has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
29
				return is_string($value);
30
			}),
31
			new \Twig_SimpleTest('array', function( $value ) {
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleTest has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
32
				return is_array($value);
33
			}),
34
			new \Twig_SimpleTest('object', function( $value, $class = '' ) {
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleTest has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
35
				$result = is_object($value);
36
				if( $class )
37
					$result = $result && ($value instanceof $class);
38
				return $result;
39
			}),
40
		];
41
	}
42
43
	public function getFilters() {
44
45
		$filters = [
46
			new \Twig_SimpleFilter('md5', 'md5'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
47
			new \Twig_SimpleFilter('sha1', 'sha1'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
48
			new \Twig_SimpleFilter('truncate', function( $str, $length, $replace = '...' ) {
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
49
		        if( isset($str) )
50
	        		return strlen($str) <= $length ? $str : substr($str, 0, $length - strip_tags($replace)) . $replace;
51
        		return null;
52
			}),
53
			new \Twig_SimpleFilter('sum', 'array_sum'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
54
			new \Twig_SimpleFilter('shuffle', 'shuffle'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
55
		];
56
57
		// include some helpful shit from yolk-core/StringHelper if we have it available
58
		if( class_exists ('\\yolk\\helpers\\StringHelper') ) {
59
			$filters = array_merge(
60
				$filters,
61
				[
62
					new \Twig_SimpleFilter('slugify', ['\\yolk\\helpers\\StringHelper', 'slugify']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
63
					new \Twig_SimpleFilter('uncamelise', ['\\yolk\\helpers\\StringHelper', 'uncamelise']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
64
					new \Twig_SimpleFilter('removeAccents', ['\\yolk\\helpers\\StringHelper', 'removeAccents']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
65
					new \Twig_SimpleFilter('ordinal', ['\\yolk\\helpers\\StringHelper', 'ordinal']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
66
					new \Twig_SimpleFilter('sizeFormat', ['\\yolk\\helpers\\StringHelper', 'sizeFormat']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
67
					new \Twig_SimpleFilter('stripControlChars', ['\\yolk\\helpers\\StringHelper', 'stripControlChars']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
68
					new \Twig_SimpleFilter('normaliseLineEndings', ['\\yolk\\helpers\\StringHelper', 'normaliseLineEndings']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
69
				]
70
			);
71
		}
72
73
		// more helpful shit from yolk-core/Inflector if we have it available
74
		if( class_exists ('\\yolk\\helpers\\Inflector') ) {
75
			$filters = array_merge(
76
				$filters,
77
				[
78
					new \Twig_SimpleFilter('pluralise', ['\\yolk\\helpers\\Inflector', 'pluralise']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
79
					new \Twig_SimpleFilter('singularise', ['\\yolk\\helpers\\Inflector', 'singularise']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
80
				]
81
			);
82
		}
83
84
		return $filters;
85
86
	}
87
88
	public function getFunctions() {
89
90
        $functions = [
91
            new \Twig_SimpleFunction('ceil', 'ceil'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
92
            new \Twig_SimpleFunction('floor', 'floor'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
93
        ];
94
95
		// include some helpful shit from yolk-core/StringHelper if we have it available
96
        if( class_exists ('\\yolk\\helpers\\StringHelper') ) {
97
			$functions = array_merge(
98
				$functions,
99
				[
100
		            new \Twig_SimpleFunction('randomHex', ['\\yolk\\helpers\\StringHelper', 'randomHex']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
101
		            new \Twig_SimpleFunction('randomString', ['\\yolk\\helpers\\StringHelper', 'randomString']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
102
				]
103
			);
104
		}
105
106
		return $functions;
107
108
	}
109
110
}
111
112
// EOF