@@ -15,23 +15,23 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @dataProvider provideDataOk |
17 | 17 | */ |
18 | - public function testValidate_variablesOk( array $defined, array $used ) { |
|
18 | + public function testValidate_variablesOk(array $defined, array $used) { |
|
19 | 19 | $usageValidator = new UsageValidator(); |
20 | - $usageValidator->trackDefinedVariables( $defined ); |
|
21 | - $usageValidator->trackUsedVariables( $used ); |
|
20 | + $usageValidator->trackDefinedVariables($defined); |
|
21 | + $usageValidator->trackUsedVariables($used); |
|
22 | 22 | $usageValidator->validate(); |
23 | 23 | |
24 | - $this->assertTrue( true ); |
|
24 | + $this->assertTrue(true); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @dataProvider provideDataInvalid |
29 | 29 | */ |
30 | - public function testValidate_variablesInvalid( array $defined, array $used ) { |
|
30 | + public function testValidate_variablesInvalid(array $defined, array $used) { |
|
31 | 31 | $usageValidator = new UsageValidator(); |
32 | - $usageValidator->trackDefinedVariables( $defined ); |
|
33 | - $usageValidator->trackUsedVariables( $used ); |
|
34 | - $this->setExpectedException( 'RangeException' ); |
|
32 | + $usageValidator->trackDefinedVariables($defined); |
|
33 | + $usageValidator->trackUsedVariables($used); |
|
34 | + $this->setExpectedException('RangeException'); |
|
35 | 35 | |
36 | 36 | $usageValidator->validate(); |
37 | 37 | } |
@@ -39,82 +39,82 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @dataProvider provideDataOk |
41 | 41 | */ |
42 | - public function testValidate_prefixesOk( array $defined, array $used ) { |
|
42 | + public function testValidate_prefixesOk(array $defined, array $used) { |
|
43 | 43 | $usageValidator = new UsageValidator(); |
44 | - $usageValidator->trackDefinedPrefixes( $defined ); |
|
45 | - $usageValidator->trackUsedPrefixes( $used ); |
|
44 | + $usageValidator->trackDefinedPrefixes($defined); |
|
45 | + $usageValidator->trackUsedPrefixes($used); |
|
46 | 46 | $usageValidator->validate(); |
47 | 47 | |
48 | - $this->assertTrue( true ); |
|
48 | + $this->assertTrue(true); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @dataProvider provideDataInvalid |
53 | 53 | */ |
54 | - public function testValidate_prefixesInvalid( array $defined, array $used ) { |
|
54 | + public function testValidate_prefixesInvalid(array $defined, array $used) { |
|
55 | 55 | $usageValidator = new UsageValidator(); |
56 | - $usageValidator->trackDefinedPrefixes( $defined ); |
|
57 | - $usageValidator->trackUsedPrefixes( $used ); |
|
58 | - $this->setExpectedException( 'RangeException' ); |
|
56 | + $usageValidator->trackDefinedPrefixes($defined); |
|
57 | + $usageValidator->trackUsedPrefixes($used); |
|
58 | + $this->setExpectedException('RangeException'); |
|
59 | 59 | |
60 | 60 | $usageValidator->validate(); |
61 | 61 | } |
62 | 62 | |
63 | 63 | public function provideDataOk() { |
64 | 64 | return array( |
65 | - array( array(), array() ), |
|
66 | - array( array( 'foo', 'bar' ), array() ), |
|
67 | - array( array( 'foo', 'bar' ), array( 'foo' ) ), |
|
68 | - array( array( 'foo', 'bar' ), array( 'foo', 'bar' ) ), |
|
65 | + array(array(), array()), |
|
66 | + array(array('foo', 'bar'), array()), |
|
67 | + array(array('foo', 'bar'), array('foo')), |
|
68 | + array(array('foo', 'bar'), array('foo', 'bar')), |
|
69 | 69 | ); |
70 | 70 | } |
71 | 71 | |
72 | 72 | public function provideDataInvalid() { |
73 | 73 | return array( |
74 | - array( array(), array( 'foo', 'bar' ) ), |
|
75 | - array( array( 'foo' ), array( 'foo', 'bar' ) ), |
|
76 | - array( array( 'bar' ), array( 'foo', 'bar' ) ), |
|
74 | + array(array(), array('foo', 'bar')), |
|
75 | + array(array('foo'), array('foo', 'bar')), |
|
76 | + array(array('bar'), array('foo', 'bar')), |
|
77 | 77 | ); |
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
81 | 81 | * @dataProvider provideTrackVariablesParsing |
82 | 82 | */ |
83 | - public function testTrackVariablesParsing( $input, $expected ) { |
|
83 | + public function testTrackVariablesParsing($input, $expected) { |
|
84 | 84 | $usageValidator = new UsageValidator(); |
85 | - $usageValidator->trackUsedVariables( $input ); |
|
86 | - $this->setExpectedException( 'RangeException', $expected ); |
|
85 | + $usageValidator->trackUsedVariables($input); |
|
86 | + $this->setExpectedException('RangeException', $expected); |
|
87 | 87 | |
88 | 88 | $usageValidator->validate(); |
89 | 89 | } |
90 | 90 | |
91 | 91 | public function provideTrackVariablesParsing() { |
92 | 92 | return array( |
93 | - array( 'foo ?abc bar', '?abc' ), |
|
94 | - array( 'foo $abc bar', '?abc' ), |
|
95 | - array( '?foo abc $bar', '?foo, ?bar' ), |
|
96 | - array( 'foo.?abc', '?abc' ), |
|
97 | - array( '?foo$bar', '?foo' ), |
|
98 | - array( '?foo AS ?bar', '?foo' ) |
|
93 | + array('foo ?abc bar', '?abc'), |
|
94 | + array('foo $abc bar', '?abc'), |
|
95 | + array('?foo abc $bar', '?foo, ?bar'), |
|
96 | + array('foo.?abc', '?abc'), |
|
97 | + array('?foo$bar', '?foo'), |
|
98 | + array('?foo AS ?bar', '?foo') |
|
99 | 99 | ); |
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | 103 | * @dataProvider provideTrackPrefixesParsing |
104 | 104 | */ |
105 | - public function testTrackPrefixesParsing( $input, $expected ) { |
|
105 | + public function testTrackPrefixesParsing($input, $expected) { |
|
106 | 106 | $usageValidator = new UsageValidator(); |
107 | - $usageValidator->trackUsedPrefixes( $input ); |
|
108 | - $this->setExpectedException( 'RangeException', $expected ); |
|
107 | + $usageValidator->trackUsedPrefixes($input); |
|
108 | + $this->setExpectedException('RangeException', $expected); |
|
109 | 109 | |
110 | 110 | $usageValidator->validate(); |
111 | 111 | } |
112 | 112 | |
113 | 113 | public function provideTrackPrefixesParsing() { |
114 | 114 | return array( |
115 | - array( 'abc foo:bar def', array( 'foo' ) ), |
|
116 | - array( 'foo:abc xxx bar:def', array( 'foo', 'bar' ) ), |
|
117 | - array( 'abc.foo:bar', array( 'foo' ) ) |
|
115 | + array('abc foo:bar def', array('foo')), |
|
116 | + array('foo:abc xxx bar:def', array('foo', 'bar')), |
|
117 | + array('abc.foo:bar', array('foo')) |
|
118 | 118 | ); |
119 | 119 | } |
120 | 120 |
@@ -15,183 +15,183 @@ |
||
15 | 15 | class GraphBuilderTest extends \PHPUnit_Framework_TestCase { |
16 | 16 | |
17 | 17 | public function testWhere() { |
18 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
18 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
19 | 19 | $this->assertSame( |
20 | 20 | $graphBuilder, |
21 | - $graphBuilder->where( '?a', '?b', '?c' ) |
|
21 | + $graphBuilder->where('?a', '?b', '?c') |
|
22 | 22 | ); |
23 | 23 | |
24 | - $this->assertEquals( ' ?a ?b ?c .', $graphBuilder->getSPARQL() ); |
|
24 | + $this->assertEquals(' ?a ?b ?c .', $graphBuilder->getSPARQL()); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public function testWhere_invalidSubject() { |
28 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
29 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
28 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
29 | + $this->setExpectedException('InvalidArgumentException'); |
|
30 | 30 | |
31 | - $graphBuilder->where( null, '?b', '?c' ); |
|
31 | + $graphBuilder->where(null, '?b', '?c'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | public function testWhere_invalidPredicate() { |
35 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
36 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
35 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
36 | + $this->setExpectedException('InvalidArgumentException'); |
|
37 | 37 | |
38 | - $graphBuilder->where( '?a', null, '?c' ); |
|
38 | + $graphBuilder->where('?a', null, '?c'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function testWhere_invalidObject() { |
42 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
43 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
42 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
43 | + $this->setExpectedException('InvalidArgumentException'); |
|
44 | 44 | |
45 | - $graphBuilder->where( '?a', '?b', null ); |
|
45 | + $graphBuilder->where('?a', '?b', null); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | public function testAlso_knownSubject() { |
49 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
50 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
49 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
50 | + $graphBuilder->where('?a', '?b', '?c'); |
|
51 | 51 | $this->assertSame( |
52 | 52 | $graphBuilder, |
53 | - $graphBuilder->also( '?x', '?y' ) |
|
53 | + $graphBuilder->also('?x', '?y') |
|
54 | 54 | ); |
55 | 55 | |
56 | - $this->assertEquals( ' ?a ?b ?c ; ?x ?y .', $graphBuilder->getSPARQL() ); |
|
56 | + $this->assertEquals(' ?a ?b ?c ; ?x ?y .', $graphBuilder->getSPARQL()); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function testAlso_knownPredicate() { |
60 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
61 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
60 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
61 | + $graphBuilder->where('?a', '?b', '?c'); |
|
62 | 62 | $this->assertSame( |
63 | 63 | $graphBuilder, |
64 | - $graphBuilder->also( '?x' ) |
|
64 | + $graphBuilder->also('?x') |
|
65 | 65 | ); |
66 | 66 | |
67 | - $this->assertEquals( ' ?a ?b ?c , ?x .', $graphBuilder->getSPARQL() ); |
|
67 | + $this->assertEquals(' ?a ?b ?c , ?x .', $graphBuilder->getSPARQL()); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | public function testAlso_unknownSubject() { |
71 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
72 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
71 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
72 | + $this->setExpectedException('InvalidArgumentException'); |
|
73 | 73 | |
74 | - $graphBuilder->also( '?x', '?y' ); |
|
74 | + $graphBuilder->also('?x', '?y'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | public function testAlso_unknownPredicate() { |
78 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
79 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
78 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
79 | + $this->setExpectedException('InvalidArgumentException'); |
|
80 | 80 | |
81 | - $graphBuilder->also( '?y' ); |
|
81 | + $graphBuilder->also('?y'); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | public function testFilter() { |
85 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
85 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
86 | 86 | $this->assertSame( |
87 | 87 | $graphBuilder, |
88 | - $graphBuilder->filter( 'AVG (?x) > 5' ) |
|
88 | + $graphBuilder->filter('AVG (?x) > 5') |
|
89 | 89 | ); |
90 | 90 | |
91 | - $this->assertEquals( ' FILTER (AVG (?x) > 5)', $graphBuilder->getSPARQL() ); |
|
91 | + $this->assertEquals(' FILTER (AVG (?x) > 5)', $graphBuilder->getSPARQL()); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | public function testFilter_invalidExpression() { |
95 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
96 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
95 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
96 | + $this->setExpectedException('InvalidArgumentException'); |
|
97 | 97 | |
98 | - $graphBuilder->filter( 'FooBar' ); |
|
98 | + $graphBuilder->filter('FooBar'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | public function testFilterExists() { |
102 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
103 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
102 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
103 | + $graphBuilder->where('?a', '?b', '?c'); |
|
104 | 104 | $this->assertSame( |
105 | 105 | $graphBuilder, |
106 | - $graphBuilder->filterExists( $graphBuilder ) |
|
106 | + $graphBuilder->filterExists($graphBuilder) |
|
107 | 107 | ); |
108 | 108 | |
109 | - $this->assertEquals( ' ?a ?b ?c . FILTER EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
109 | + $this->assertEquals(' ?a ?b ?c . FILTER EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | public function testFilterExists_triple() { |
113 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
113 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
114 | 114 | $this->assertSame( |
115 | 115 | $graphBuilder, |
116 | - $graphBuilder->filterExists( '?a', '?b', '?c' ) |
|
116 | + $graphBuilder->filterExists('?a', '?b', '?c') |
|
117 | 117 | ); |
118 | 118 | |
119 | - $this->assertEquals( ' FILTER EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
119 | + $this->assertEquals(' FILTER EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | public function testFilterNotExists() { |
123 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
124 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
123 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
124 | + $graphBuilder->where('?a', '?b', '?c'); |
|
125 | 125 | $this->assertSame( |
126 | 126 | $graphBuilder, |
127 | - $graphBuilder->filterNotExists( $graphBuilder ) |
|
127 | + $graphBuilder->filterNotExists($graphBuilder) |
|
128 | 128 | ); |
129 | 129 | |
130 | - $this->assertEquals( ' ?a ?b ?c . FILTER NOT EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
130 | + $this->assertEquals(' ?a ?b ?c . FILTER NOT EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | public function testFilterNotExists_triple() { |
134 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
134 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
135 | 135 | $this->assertSame( |
136 | 136 | $graphBuilder, |
137 | - $graphBuilder->filterNotExists( '?a', '?b', '?c' ) |
|
137 | + $graphBuilder->filterNotExists('?a', '?b', '?c') |
|
138 | 138 | ); |
139 | 139 | |
140 | - $this->assertEquals( ' FILTER NOT EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
140 | + $this->assertEquals(' FILTER NOT EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | public function testOptional() { |
144 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
145 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
144 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
145 | + $graphBuilder->where('?a', '?b', '?c'); |
|
146 | 146 | $this->assertSame( |
147 | 147 | $graphBuilder, |
148 | - $graphBuilder->optional( $graphBuilder ) |
|
148 | + $graphBuilder->optional($graphBuilder) |
|
149 | 149 | ); |
150 | 150 | |
151 | - $this->assertEquals( ' ?a ?b ?c . OPTIONAL { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
151 | + $this->assertEquals(' ?a ?b ?c . OPTIONAL { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | public function testOptional_triple() { |
155 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
155 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
156 | 156 | $this->assertSame( |
157 | 157 | $graphBuilder, |
158 | - $graphBuilder->optional( '?a', '?b', '?c' ) |
|
158 | + $graphBuilder->optional('?a', '?b', '?c') |
|
159 | 159 | ); |
160 | 160 | |
161 | - $this->assertEquals( ' OPTIONAL { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
161 | + $this->assertEquals(' OPTIONAL { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | public function testUnion() { |
165 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
166 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
165 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
166 | + $graphBuilder->where('?a', '?b', '?c'); |
|
167 | 167 | $this->assertSame( |
168 | 168 | $graphBuilder, |
169 | - $graphBuilder->union( $graphBuilder, $graphBuilder ) |
|
169 | + $graphBuilder->union($graphBuilder, $graphBuilder) |
|
170 | 170 | ); |
171 | 171 | |
172 | - $this->assertEquals( ' ?a ?b ?c . { ?a ?b ?c . } UNION { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
172 | + $this->assertEquals(' ?a ?b ?c . { ?a ?b ?c . } UNION { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | public function testSubquery() { |
176 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
176 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
177 | 177 | $queryBuilder = new QueryBuilder(); |
178 | - $queryBuilder->where( '?a', '?b', '?c' ); |
|
178 | + $queryBuilder->where('?a', '?b', '?c'); |
|
179 | 179 | $this->assertSame( |
180 | 180 | $graphBuilder, |
181 | - $graphBuilder->subquery( $queryBuilder ) |
|
181 | + $graphBuilder->subquery($queryBuilder) |
|
182 | 182 | ); |
183 | 183 | |
184 | - $this->assertEquals( ' { SELECT * WHERE { ?a ?b ?c . } }', $graphBuilder->getSPARQL() ); |
|
184 | + $this->assertEquals(' { SELECT * WHERE { ?a ?b ?c . } }', $graphBuilder->getSPARQL()); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | public function testGetSPARQL() { |
188 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
189 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
190 | - $graphBuilder->also( '?x', '?y' ); |
|
191 | - $graphBuilder->also( '?z' ); |
|
192 | - $graphBuilder->where( '?a', '?b', '?z' ); |
|
188 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
189 | + $graphBuilder->where('?a', '?b', '?c'); |
|
190 | + $graphBuilder->also('?x', '?y'); |
|
191 | + $graphBuilder->also('?z'); |
|
192 | + $graphBuilder->where('?a', '?b', '?z'); |
|
193 | 193 | |
194 | - $this->assertEquals( ' ?a ?b ?c , ?z ; ?x ?y , ?z .', $graphBuilder->getSPARQL() ); |
|
194 | + $this->assertEquals(' ?a ?b ?c , ?z ; ?x ?y , ?z .', $graphBuilder->getSPARQL()); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | } |
@@ -15,84 +15,84 @@ |
||
15 | 15 | /** |
16 | 16 | * @dataProvider provideValidExpressions |
17 | 17 | */ |
18 | - public function testValidate_validExpressions( $expression, $options ) { |
|
18 | + public function testValidate_validExpressions($expression, $options) { |
|
19 | 19 | $expressionValidator = new ExpressionValidator(); |
20 | - $expressionValidator->validate( $expression, $options ); |
|
20 | + $expressionValidator->validate($expression, $options); |
|
21 | 21 | |
22 | - $this->assertTrue( true ); |
|
22 | + $this->assertTrue(true); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function provideValidExpressions() { |
26 | 26 | return array( |
27 | - array( '?a', ExpressionValidator::VALIDATE_VARIABLE ), |
|
28 | - array( '$b', ExpressionValidator::VALIDATE_VARIABLE ), |
|
29 | - array( 'http://www.example.com/test#', ExpressionValidator::VALIDATE_IRI ), |
|
30 | - array( 'abc', ExpressionValidator::VALIDATE_PREFIX ), |
|
31 | - array( 'test:FooBar', ExpressionValidator::VALIDATE_PREFIXED_IRI ), |
|
32 | - array( '<http://www.example.com/test#>', ExpressionValidator::VALIDATE_PREFIXED_IRI ), |
|
33 | - array( '123', ExpressionValidator::VALIDATE_NATIVE ), |
|
34 | - array( '"Foo bar"', ExpressionValidator::VALIDATE_NATIVE ), |
|
35 | - array( 'foaf:knows/foaf:name', ExpressionValidator::VALIDATE_PATH ), |
|
36 | - array( 'foaf:knows/foaf:knows/foaf:name', ExpressionValidator::VALIDATE_PATH ), |
|
37 | - array( 'foaf:knows/^foaf:knows', ExpressionValidator::VALIDATE_PATH ), |
|
38 | - array( 'foaf:knows+/foaf:name', ExpressionValidator::VALIDATE_PATH ), |
|
39 | - array( '(ex:motherOf|ex:fatherOf)+', ExpressionValidator::VALIDATE_PATH ), |
|
40 | - array( 'rdf:type/rdfs:subClassOf*', ExpressionValidator::VALIDATE_PATH ), |
|
41 | - array( '^rdf:type', ExpressionValidator::VALIDATE_PATH ), |
|
42 | - array( '!(rdf:type|^rdf:type)', ExpressionValidator::VALIDATE_PATH ), |
|
43 | - array( 'CONTAINS (?x, "test"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION ), |
|
44 | - array( '?abc', ExpressionValidator::VALIDATE_FUNCTION ), |
|
45 | - array( '?x + ?y > ?z', ExpressionValidator::VALIDATE_FUNCTION ), |
|
46 | - array( '?x * ?x < ?y', ExpressionValidator::VALIDATE_FUNCTION ), |
|
47 | - array( 'CONTAINS (?x, ")))"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION ), |
|
48 | - array( '<http://www.example.com/test#nyan> ?p ?q', ExpressionValidator::VALIDATE_FUNCTION ), |
|
49 | - array( '(COUNT (?x) AS ?count)', ExpressionValidator::VALIDATE_FUNCTION_AS ), |
|
27 | + array('?a', ExpressionValidator::VALIDATE_VARIABLE), |
|
28 | + array('$b', ExpressionValidator::VALIDATE_VARIABLE), |
|
29 | + array('http://www.example.com/test#', ExpressionValidator::VALIDATE_IRI), |
|
30 | + array('abc', ExpressionValidator::VALIDATE_PREFIX), |
|
31 | + array('test:FooBar', ExpressionValidator::VALIDATE_PREFIXED_IRI), |
|
32 | + array('<http://www.example.com/test#>', ExpressionValidator::VALIDATE_PREFIXED_IRI), |
|
33 | + array('123', ExpressionValidator::VALIDATE_NATIVE), |
|
34 | + array('"Foo bar"', ExpressionValidator::VALIDATE_NATIVE), |
|
35 | + array('foaf:knows/foaf:name', ExpressionValidator::VALIDATE_PATH), |
|
36 | + array('foaf:knows/foaf:knows/foaf:name', ExpressionValidator::VALIDATE_PATH), |
|
37 | + array('foaf:knows/^foaf:knows', ExpressionValidator::VALIDATE_PATH), |
|
38 | + array('foaf:knows+/foaf:name', ExpressionValidator::VALIDATE_PATH), |
|
39 | + array('(ex:motherOf|ex:fatherOf)+', ExpressionValidator::VALIDATE_PATH), |
|
40 | + array('rdf:type/rdfs:subClassOf*', ExpressionValidator::VALIDATE_PATH), |
|
41 | + array('^rdf:type', ExpressionValidator::VALIDATE_PATH), |
|
42 | + array('!(rdf:type|^rdf:type)', ExpressionValidator::VALIDATE_PATH), |
|
43 | + array('CONTAINS (?x, "test"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION), |
|
44 | + array('?abc', ExpressionValidator::VALIDATE_FUNCTION), |
|
45 | + array('?x + ?y > ?z', ExpressionValidator::VALIDATE_FUNCTION), |
|
46 | + array('?x * ?x < ?y', ExpressionValidator::VALIDATE_FUNCTION), |
|
47 | + array('CONTAINS (?x, ")))"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION), |
|
48 | + array('<http://www.example.com/test#nyan> ?p ?q', ExpressionValidator::VALIDATE_FUNCTION), |
|
49 | + array('(COUNT (?x) AS ?count)', ExpressionValidator::VALIDATE_FUNCTION_AS), |
|
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @dataProvider provideInvalidExpressions |
55 | 55 | */ |
56 | - public function testValidate_invalidExpressions( $expression, $options, $errorMessage ) { |
|
56 | + public function testValidate_invalidExpressions($expression, $options, $errorMessage) { |
|
57 | 57 | $expressionValidator = new ExpressionValidator(); |
58 | - $this->setExpectedException( 'InvalidArgumentException', $errorMessage ); |
|
58 | + $this->setExpectedException('InvalidArgumentException', $errorMessage); |
|
59 | 59 | |
60 | - $expressionValidator->validate( $expression, $options ); |
|
60 | + $expressionValidator->validate($expression, $options); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | public function provideInvalidExpressions() { |
64 | 64 | return array( |
65 | - array( 'nyan', ExpressionValidator::VALIDATE_VARIABLE, 'variable' ), |
|
66 | - array( '<http://www.example.com/test#>', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
67 | - array( 'http://www.example.com/test#> foo bar', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
68 | - array( '<abc><>', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
69 | - array( 'http://www.example.com/te st#', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
70 | - array( 'http://www.example.com/test#ab\cd', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
71 | - array( 'http://www.example.com/test#ab|cd', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
72 | - array( 'ab:cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix' ), |
|
73 | - array( 'ab/cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix' ), |
|
74 | - array( 'ab cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix' ), |
|
75 | - array( 'foobar', ExpressionValidator::VALIDATE_PREFIXED_IRI, 'prefixed IRI' ), |
|
76 | - array( 'test:Foo:Bar', ExpressionValidator::VALIDATE_PREFIXED_IRI, 'prefixed IRI' ), |
|
77 | - array( '"abc', ExpressionValidator::VALIDATE_NATIVE, 'native' ), |
|
78 | - array( 'abc123', ExpressionValidator::VALIDATE_NATIVE, 'native' ), |
|
79 | - array( 'foobar (?x > ?y)', ExpressionValidator::VALIDATE_FUNCTION, 'function' ), |
|
80 | - array( '(RAND ())', ExpressionValidator::VALIDATE_FUNCTION, 'function' ), |
|
81 | - array( 'COUNT (?x) + 5) * ?a', ExpressionValidator::VALIDATE_FUNCTION, 'function' ), |
|
82 | - array( 'CONTAINS (?x, "test"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment' ), |
|
83 | - array( '?x + ?y > ?z', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment' ), |
|
84 | - array( ' AS ?abc', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment' ), |
|
85 | - array( 'COUNT (?x) AS ?count', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment' ), |
|
86 | - array( '', ExpressionValidator::VALIDATE_ALL, 'or a' ), |
|
87 | - array( ' ', ExpressionValidator::VALIDATE_ALL, 'or a' ), |
|
65 | + array('nyan', ExpressionValidator::VALIDATE_VARIABLE, 'variable'), |
|
66 | + array('<http://www.example.com/test#>', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
67 | + array('http://www.example.com/test#> foo bar', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
68 | + array('<abc><>', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
69 | + array('http://www.example.com/te st#', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
70 | + array('http://www.example.com/test#ab\cd', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
71 | + array('http://www.example.com/test#ab|cd', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
72 | + array('ab:cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix'), |
|
73 | + array('ab/cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix'), |
|
74 | + array('ab cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix'), |
|
75 | + array('foobar', ExpressionValidator::VALIDATE_PREFIXED_IRI, 'prefixed IRI'), |
|
76 | + array('test:Foo:Bar', ExpressionValidator::VALIDATE_PREFIXED_IRI, 'prefixed IRI'), |
|
77 | + array('"abc', ExpressionValidator::VALIDATE_NATIVE, 'native'), |
|
78 | + array('abc123', ExpressionValidator::VALIDATE_NATIVE, 'native'), |
|
79 | + array('foobar (?x > ?y)', ExpressionValidator::VALIDATE_FUNCTION, 'function'), |
|
80 | + array('(RAND ())', ExpressionValidator::VALIDATE_FUNCTION, 'function'), |
|
81 | + array('COUNT (?x) + 5) * ?a', ExpressionValidator::VALIDATE_FUNCTION, 'function'), |
|
82 | + array('CONTAINS (?x, "test"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment'), |
|
83 | + array('?x + ?y > ?z', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment'), |
|
84 | + array(' AS ?abc', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment'), |
|
85 | + array('COUNT (?x) AS ?count', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment'), |
|
86 | + array('', ExpressionValidator::VALIDATE_ALL, 'or a'), |
|
87 | + array(' ', ExpressionValidator::VALIDATE_ALL, 'or a'), |
|
88 | 88 | ); |
89 | 89 | } |
90 | 90 | |
91 | 91 | public function testValidate_invalidArgument() { |
92 | 92 | $expressionValidator = new ExpressionValidator(); |
93 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
93 | + $this->setExpectedException('InvalidArgumentException'); |
|
94 | 94 | |
95 | - $expressionValidator->validate( null, ExpressionValidator::VALIDATE_ALL ); |
|
95 | + $expressionValidator->validate(null, ExpressionValidator::VALIDATE_ALL); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | } |
@@ -19,25 +19,25 @@ |
||
19 | 19 | ); |
20 | 20 | |
21 | 21 | public function testConstructor() { |
22 | - $prefixBuilder = new QueryPrefixBuilder( self::$prefixes, new UsageValidator() ); |
|
22 | + $prefixBuilder = new QueryPrefixBuilder(self::$prefixes, new UsageValidator()); |
|
23 | 23 | |
24 | - $this->assertEquals( self::$prefixes, $prefixBuilder->getPrefixes() ); |
|
24 | + $this->assertEquals(self::$prefixes, $prefixBuilder->getPrefixes()); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public function testConstructor_invalidIRI() { |
28 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
28 | + $this->setExpectedException('InvalidArgumentException'); |
|
29 | 29 | |
30 | - new QueryPrefixBuilder( array( 'bar' => null ), new UsageValidator() ); |
|
30 | + new QueryPrefixBuilder(array('bar' => null), new UsageValidator()); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function testConstructor_invalidPrefix() { |
34 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
34 | + $this->setExpectedException('InvalidArgumentException'); |
|
35 | 35 | |
36 | - new QueryPrefixBuilder( array( 4 => 'http://foo.bar.com/nyan#' ), new UsageValidator() ); |
|
36 | + new QueryPrefixBuilder(array(4 => 'http://foo.bar.com/nyan#'), new UsageValidator()); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public function testGetSPARQL() { |
40 | - $prefixBuilder = new QueryPrefixBuilder( self::$prefixes, new UsageValidator() ); |
|
40 | + $prefixBuilder = new QueryPrefixBuilder(self::$prefixes, new UsageValidator()); |
|
41 | 41 | |
42 | 42 | $this->assertEquals( |
43 | 43 | 'PREFIX test: <http://www.example.com/test#> PREFIX foo: <http://www.foo.org/bar#> ', |
@@ -14,87 +14,87 @@ |
||
14 | 14 | class QueryModifierBuilderTest extends \PHPUnit_Framework_TestCase { |
15 | 15 | |
16 | 16 | public function testGroupByModifier() { |
17 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
18 | - $queryBuilder->groupBy( array( '?test' ) ); |
|
17 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
18 | + $queryBuilder->groupBy(array('?test')); |
|
19 | 19 | |
20 | - $this->assertEquals( ' GROUP BY ?test', $queryBuilder->getSPARQL() ); |
|
20 | + $this->assertEquals(' GROUP BY ?test', $queryBuilder->getSPARQL()); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function testGroupByModifier_invalidArgument() { |
24 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
25 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
24 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
25 | + $this->setExpectedException('InvalidArgumentException'); |
|
26 | 26 | |
27 | - $queryBuilder->groupBy( array( null ) ); |
|
27 | + $queryBuilder->groupBy(array(null)); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function testHavingModifier() { |
31 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
32 | - $queryBuilder->having( '?test' ); |
|
31 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
32 | + $queryBuilder->having('?test'); |
|
33 | 33 | |
34 | - $this->assertEquals( ' HAVING (?test)', $queryBuilder->getSPARQL() ); |
|
34 | + $this->assertEquals(' HAVING (?test)', $queryBuilder->getSPARQL()); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function testHavingModifier_invalidArgument() { |
38 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
39 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
38 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
39 | + $this->setExpectedException('InvalidArgumentException'); |
|
40 | 40 | |
41 | - $queryBuilder->having( null ); |
|
41 | + $queryBuilder->having(null); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function testOrderByModifier() { |
45 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
46 | - $queryBuilder->orderBy( '?test' ); |
|
45 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
46 | + $queryBuilder->orderBy('?test'); |
|
47 | 47 | |
48 | - $this->assertEquals( ' ORDER BY ASC (?test)', $queryBuilder->getSPARQL() ); |
|
48 | + $this->assertEquals(' ORDER BY ASC (?test)', $queryBuilder->getSPARQL()); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | public function testOrderByDescModifier() { |
52 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
53 | - $queryBuilder->orderBy( '?test', 'DESC' ); |
|
52 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
53 | + $queryBuilder->orderBy('?test', 'DESC'); |
|
54 | 54 | |
55 | - $this->assertEquals( ' ORDER BY DESC (?test)', $queryBuilder->getSPARQL() ); |
|
55 | + $this->assertEquals(' ORDER BY DESC (?test)', $queryBuilder->getSPARQL()); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | public function testOrderByModifier_invalidArgument() { |
59 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
60 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
59 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
60 | + $this->setExpectedException('InvalidArgumentException'); |
|
61 | 61 | |
62 | - $queryBuilder->orderBy( null ); |
|
62 | + $queryBuilder->orderBy(null); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | public function testOrderByModifier_invalidDirection() { |
66 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
67 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
66 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
67 | + $this->setExpectedException('InvalidArgumentException'); |
|
68 | 68 | |
69 | - $queryBuilder->orderBy( '?test', 'FOO' ); |
|
69 | + $queryBuilder->orderBy('?test', 'FOO'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | public function testLimitModifier() { |
73 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
74 | - $queryBuilder->limit( 42 ); |
|
73 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
74 | + $queryBuilder->limit(42); |
|
75 | 75 | |
76 | - $this->assertEquals( ' LIMIT 42', $queryBuilder->getSPARQL() ); |
|
76 | + $this->assertEquals(' LIMIT 42', $queryBuilder->getSPARQL()); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | public function testLimitModifier_invalidArgument() { |
80 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
81 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
80 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
81 | + $this->setExpectedException('InvalidArgumentException'); |
|
82 | 82 | |
83 | - $queryBuilder->limit( null ); |
|
83 | + $queryBuilder->limit(null); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | public function testOffsetModifier() { |
87 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
88 | - $queryBuilder->offset( 42 ); |
|
87 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
88 | + $queryBuilder->offset(42); |
|
89 | 89 | |
90 | - $this->assertEquals( ' OFFSET 42', $queryBuilder->getSPARQL() ); |
|
90 | + $this->assertEquals(' OFFSET 42', $queryBuilder->getSPARQL()); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | public function testOffsetModifier_invalidArgument() { |
94 | - $queryBuilder = new QueryModifierBuilder( new UsageValidator() ); |
|
95 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
94 | + $queryBuilder = new QueryModifierBuilder(new UsageValidator()); |
|
95 | + $this->setExpectedException('InvalidArgumentException'); |
|
96 | 96 | |
97 | - $queryBuilder->offset( null ); |
|
97 | + $queryBuilder->offset(null); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | } |
@@ -15,20 +15,20 @@ |
||
15 | 15 | /** |
16 | 16 | * @dataProvider provideTestFormat |
17 | 17 | */ |
18 | - public function testFormat( $expected, $input ) { |
|
18 | + public function testFormat($expected, $input) { |
|
19 | 19 | $formatter = new QueryFormatter(); |
20 | 20 | |
21 | - $this->assertEquals( $expected, $formatter->format( $input ) ); |
|
21 | + $this->assertEquals($expected, $formatter->format($input)); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function provideTestFormat() { |
25 | 25 | return array( |
26 | - 'new line before prefix' => array( "PREFIX abc\nPREFIX\n", 'PREFIX abc PREFIX' ), |
|
27 | - 'new lines before select' => array( "foobar\n\nSELECT xyz\n", 'foobar SELECT xyz' ), |
|
28 | - 'new line after brackets' => array( "abc {\n}\ndef\n", 'abc { } def' ), |
|
29 | - 'indentation by brackets' => array( "{\n\t{\n\t\tfoobar .\n\t}\n\tnyan .\n}\n", '{ { foobar . } nyan . }' ), |
|
30 | - 'strings get escaped' => array( '"abc { def } hij" <abc { xyy > <"a{2>' . "\n", '"abc { def } hij" <abc { xyy > <"a{2>' ), |
|
31 | - 'spaces before characters' => array( "a .\nb =c (d <e {\n\tf ?g \$h\n", 'a.b=c(d<e{f?g$h' ) |
|
26 | + 'new line before prefix' => array("PREFIX abc\nPREFIX\n", 'PREFIX abc PREFIX'), |
|
27 | + 'new lines before select' => array("foobar\n\nSELECT xyz\n", 'foobar SELECT xyz'), |
|
28 | + 'new line after brackets' => array("abc {\n}\ndef\n", 'abc { } def'), |
|
29 | + 'indentation by brackets' => array("{\n\t{\n\t\tfoobar .\n\t}\n\tnyan .\n}\n", '{ { foobar . } nyan . }'), |
|
30 | + 'strings get escaped' => array('"abc { def } hij" <abc { xyy > <"a{2>' . "\n", '"abc { def } hij" <abc { xyy > <"a{2>'), |
|
31 | + 'spaces before characters' => array("a .\nb =c (d <e {\n\tf ?g \$h\n", 'a.b=c(d<e{f?g$h') |
|
32 | 32 | ); |
33 | 33 | } |
34 | 34 |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * @param string $userAgent |
22 | 22 | */ |
23 | - public function __construct( $userAgent ) { |
|
23 | + public function __construct($userAgent) { |
|
24 | 24 | $this->ch = curl_init(); |
25 | - curl_setopt( $this->ch, CURLOPT_USERAGENT, $userAgent ); |
|
26 | - curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, true ); |
|
27 | - curl_setopt( $this->ch, CURLOPT_FOLLOWLOCATION, true ); |
|
25 | + curl_setopt($this->ch, CURLOPT_USERAGENT, $userAgent); |
|
26 | + curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); |
|
27 | + curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function __destruct() { |
31 | - curl_close( $this->ch ); |
|
31 | + curl_close($this->ch); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -37,16 +37,16 @@ discard block |
||
37 | 37 | * @return string |
38 | 38 | * @throws RuntimeException |
39 | 39 | */ |
40 | - public function request( $url, array $params = array() ) { |
|
41 | - curl_setopt( $this->ch, CURLOPT_URL, $url . '?' . http_build_query( $params ) ); |
|
42 | - curl_setopt( $this->ch, CURLOPT_HTTPGET, true ); |
|
40 | + public function request($url, array $params = array()) { |
|
41 | + curl_setopt($this->ch, CURLOPT_URL, $url . '?' . http_build_query($params)); |
|
42 | + curl_setopt($this->ch, CURLOPT_HTTPGET, true); |
|
43 | 43 | |
44 | - $response = curl_exec( $this->ch ); |
|
44 | + $response = curl_exec($this->ch); |
|
45 | 45 | |
46 | - if ( curl_errno( $this->ch ) ) { |
|
47 | - throw new RuntimeException( curl_error( $this->ch ), curl_errno( $this->ch ) ); |
|
48 | - } else if ( curl_getinfo( $this->ch, CURLINFO_HTTP_CODE ) >= 400 ) { |
|
49 | - throw new RuntimeException( 'HTTP error: ' . $url, curl_getinfo( $this->ch, CURLINFO_HTTP_CODE ) ); |
|
46 | + if (curl_errno($this->ch)) { |
|
47 | + throw new RuntimeException(curl_error($this->ch), curl_errno($this->ch)); |
|
48 | + } else if (curl_getinfo($this->ch, CURLINFO_HTTP_CODE) >= 400) { |
|
49 | + throw new RuntimeException('HTTP error: ' . $url, curl_getinfo($this->ch, CURLINFO_HTTP_CODE)); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | return $response; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | private $usageValidator; |
29 | 29 | |
30 | - public function __construct( UsageValidator $usageValidator ) { |
|
30 | + public function __construct(UsageValidator $usageValidator) { |
|
31 | 31 | $this->expressionValidator = new ExpressionValidator(); |
32 | 32 | $this->usageValidator = $usageValidator; |
33 | 33 | } |
@@ -37,16 +37,16 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param string[] $expressions |
39 | 39 | */ |
40 | - public function groupBy( array $expressions ) { |
|
41 | - foreach ( $expressions as $expression ) { |
|
42 | - $this->expressionValidator->validate( $expression, |
|
40 | + public function groupBy(array $expressions) { |
|
41 | + foreach ($expressions as $expression) { |
|
42 | + $this->expressionValidator->validate($expression, |
|
43 | 43 | ExpressionValidator::VALIDATE_VARIABLE | ExpressionValidator::VALIDATE_FUNCTION_AS |
44 | 44 | ); |
45 | 45 | } |
46 | 46 | |
47 | - $expression = implode( ' ', $expressions ); |
|
48 | - $this->usageValidator->trackUsedPrefixes( $expression ); |
|
49 | - $this->usageValidator->trackUsedVariables( $expression ); |
|
47 | + $expression = implode(' ', $expressions); |
|
48 | + $this->usageValidator->trackUsedPrefixes($expression); |
|
49 | + $this->usageValidator->trackUsedVariables($expression); |
|
50 | 50 | $this->modifiers['GROUP BY'] = $expression; |
51 | 51 | } |
52 | 52 | |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @param string $expression |
57 | 57 | */ |
58 | - public function having( $expression ) { |
|
59 | - $this->expressionValidator->validate( $expression, ExpressionValidator::VALIDATE_FUNCTION ); |
|
58 | + public function having($expression) { |
|
59 | + $this->expressionValidator->validate($expression, ExpressionValidator::VALIDATE_FUNCTION); |
|
60 | 60 | |
61 | - $this->usageValidator->trackUsedPrefixes( $expression ); |
|
62 | - $this->usageValidator->trackUsedVariables( $expression ); |
|
61 | + $this->usageValidator->trackUsedPrefixes($expression); |
|
62 | + $this->usageValidator->trackUsedVariables($expression); |
|
63 | 63 | $this->modifiers['HAVING'] = '(' . $expression . ')'; |
64 | 64 | } |
65 | 65 | |
@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | * @param string $direction one of ASC or DESC |
71 | 71 | * @throws InvalidArgumentException |
72 | 72 | */ |
73 | - public function orderBy( $expression, $direction = 'ASC' ) { |
|
74 | - $direction = strtoupper( $direction ); |
|
75 | - if ( !in_array( $direction, array( 'ASC', 'DESC' ) ) ) { |
|
76 | - throw new InvalidArgumentException( '$direction has to be either ASC or DESC' ); |
|
73 | + public function orderBy($expression, $direction = 'ASC') { |
|
74 | + $direction = strtoupper($direction); |
|
75 | + if (!in_array($direction, array('ASC', 'DESC'))) { |
|
76 | + throw new InvalidArgumentException('$direction has to be either ASC or DESC'); |
|
77 | 77 | } |
78 | 78 | |
79 | - $this->expressionValidator->validate( $expression, |
|
79 | + $this->expressionValidator->validate($expression, |
|
80 | 80 | ExpressionValidator::VALIDATE_VARIABLE | ExpressionValidator::VALIDATE_FUNCTION |
81 | 81 | ); |
82 | 82 | |
83 | - $this->usageValidator->trackUsedPrefixes( $expression ); |
|
84 | - $this->usageValidator->trackUsedVariables( $expression ); |
|
83 | + $this->usageValidator->trackUsedPrefixes($expression); |
|
84 | + $this->usageValidator->trackUsedVariables($expression); |
|
85 | 85 | $this->modifiers['ORDER BY'] = $direction . ' (' . $expression . ')'; |
86 | 86 | } |
87 | 87 | |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | * @param int $limit |
92 | 92 | * @throws InvalidArgumentException |
93 | 93 | */ |
94 | - public function limit( $limit ) { |
|
95 | - if ( !is_int( $limit ) ) { |
|
96 | - throw new InvalidArgumentException( '$limit has to be an integer' ); |
|
94 | + public function limit($limit) { |
|
95 | + if (!is_int($limit)) { |
|
96 | + throw new InvalidArgumentException('$limit has to be an integer'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | $this->modifiers['LIMIT'] = $limit; |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param int $offset |
106 | 106 | * @throws InvalidArgumentException |
107 | 107 | */ |
108 | - public function offset( $offset ) { |
|
109 | - if ( !is_int( $offset ) ) { |
|
110 | - throw new InvalidArgumentException( '$offset has to be an integer' ); |
|
108 | + public function offset($offset) { |
|
109 | + if (!is_int($offset)) { |
|
110 | + throw new InvalidArgumentException('$offset has to be an integer'); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $this->modifiers['OFFSET'] = $offset; |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function getSPARQL() { |
122 | 122 | $modifiers = $this->modifiers; |
123 | - return implode( array_map( function( $key ) use ( $modifiers ) { |
|
124 | - if ( isset( $modifiers[$key] ) ) { |
|
123 | + return implode(array_map(function($key) use ($modifiers) { |
|
124 | + if (isset($modifiers[$key])) { |
|
125 | 125 | return ' ' . $key . ' ' . $modifiers[$key]; |
126 | 126 | } |
127 | - }, array( 'GROUP BY', 'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET' ) ) ); |
|
127 | + }, array('GROUP BY', 'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET'))); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | } |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @param string[] $prefixes |
32 | 32 | */ |
33 | - public function __construct( array $prefixes, UsageValidator $usageValidator ) { |
|
33 | + public function __construct(array $prefixes, UsageValidator $usageValidator) { |
|
34 | 34 | $this->expressionValidator = new ExpressionValidator(); |
35 | 35 | $this->usageValidator = $usageValidator; |
36 | - $this->setPrefixes( $prefixes ); |
|
36 | + $this->setPrefixes($prefixes); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | * @param string[] $prefixes |
43 | 43 | * @throws InvalidArgumentException |
44 | 44 | */ |
45 | - private function setPrefixes( array $prefixes ) { |
|
46 | - foreach ( $prefixes as $prefix => $iri ) { |
|
47 | - $this->expressionValidator->validate( $prefix, ExpressionValidator::VALIDATE_PREFIX ); |
|
48 | - $this->expressionValidator->validate( $iri, ExpressionValidator::VALIDATE_IRI ); |
|
45 | + private function setPrefixes(array $prefixes) { |
|
46 | + foreach ($prefixes as $prefix => $iri) { |
|
47 | + $this->expressionValidator->validate($prefix, ExpressionValidator::VALIDATE_PREFIX); |
|
48 | + $this->expressionValidator->validate($iri, ExpressionValidator::VALIDATE_IRI); |
|
49 | 49 | |
50 | 50 | $this->prefixes[$prefix] = $iri; |
51 | 51 | } |
52 | 52 | |
53 | - $this->usageValidator->trackDefinedPrefixes( array_keys( $this->prefixes ) ); |
|
53 | + $this->usageValidator->trackDefinedPrefixes(array_keys($this->prefixes)); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * @return string |
67 | 67 | */ |
68 | 68 | public function getSPARQL() { |
69 | - return implode( array_map( function( $prefix, $iri ) { |
|
69 | + return implode(array_map(function($prefix, $iri) { |
|
70 | 70 | return 'PREFIX ' . $prefix . ': <' . $iri . '> '; |
71 | - }, array_keys( $this->prefixes ), $this->prefixes ) ); |
|
71 | + }, array_keys($this->prefixes), $this->prefixes)); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | } |