Skip to content

Commit c46e938

Browse files
Merged Pull Request '#29 code-style->main : Apply code style fixes'
Apply code style fixes
2 parents 589f647 + e110a93 commit c46e938

35 files changed

+1409
-1405
lines changed

.php-cs-fixer.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
return (new PhpCsFixer\Config())
4+
->setRules([
5+
'@PER' => true,
6+
'@PSR12' => true,
7+
'@Symfony' => true,
8+
'@PhpCsFixer' => true,
9+
'no_useless_return' => false,
10+
'php_unit_test_class_requires_covers' => false,
11+
'php_unit_internal_class' => false,
12+
'phpdoc_align' => false,
13+
'phpdoc_no_empty_return' => false,
14+
'phpdoc_separation' => false,
15+
'yoda_style' => false,
16+
'trailing_comma_in_multiline' => false,
17+
'multiline_whitespace_before_semicolons' => [
18+
'strategy' => 'no_multi_line'
19+
],
20+
'concat_space' => [
21+
'spacing' => 'one'
22+
],
23+
'not_operator_with_space' => false,
24+
'operator_linebreak' => [
25+
'position' => 'end',
26+
'only_booleans' => true
27+
],
28+
'blank_line_before_statement' => [
29+
'statements' => [
30+
'return',
31+
'throw',
32+
'try',
33+
'declare'
34+
]
35+
]
36+
])
37+
->setFinder(PhpCsFixer\Finder::create()
38+
->in([
39+
__DIR__ . '/src',
40+
__DIR__ . '/tests/classes',
41+
__DIR__ . '/examples',
42+
])
43+
);

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
},
3232
"require-dev": {
3333
"kint-php/kint": "^3.3",
34-
"phpunit/phpunit": "*"
34+
"phpunit/phpunit": "*",
35+
"friendsofphp/php-cs-fixer": "^3.39"
3536
},
3637
"autoload": {
3738
"psr-4": {

examples/CustomFlowElement.php

Lines changed: 92 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* such notice(s) shall fulfill the requirements of that article.
2222
* ********************************************************************* */
2323

24-
/**
24+
/*
2525
* @example CustomFlowElement.php
2626
*
2727
* This example demonstrates the creation of a custom flow element. In this case
@@ -31,180 +31,173 @@
3131
* which gets a user's geolocation and saves the latitude as a cookie.
3232
* This latitude is also then passed in to the FlowData to calculate if
3333
* a person is in the northern or southern hemispheres.
34-
34+
*
3535
*/
3636

37-
38-
use fiftyone\pipeline\core\PipelineBuilder;
3937
use fiftyone\pipeline\core\BasicListEvidenceKeyFilter;
40-
use fiftyone\pipeline\core\FlowElement;
4138
use fiftyone\pipeline\core\ElementDataDictionary;
39+
use fiftyone\pipeline\core\FlowElement;
40+
use fiftyone\pipeline\core\PipelineBuilder;
4241

4342
// Function to get star sign from month and day
4443
function getStarSign($month, $day)
4544
{
4645
if (($month == 1 && $day <= 20) || ($month == 12 && $day >= 22)) {
47-
return "capricorn";
48-
} elseif (($month == 1 && $day >= 21) || ($month == 2 && $day <= 18)) {
49-
return "aquarius";
50-
} elseif (($month == 2 && $day >= 19) || ($month == 3 && $day <= 20)) {
51-
return "pisces";
52-
} elseif (($month == 3 && $day >= 21) || ($month == 4 && $day <= 20)) {
53-
return "aries";
54-
} elseif (($month == 4 && $day >= 21) || ($month == 5 && $day <= 20)) {
55-
return "taurus";
56-
} elseif (($month == 5 && $day >= 21) || ($month == 6 && $day <= 20)) {
57-
return "gemini";
58-
} elseif (($month == 6 && $day >= 22) || ($month == 7 && $day <= 22)) {
59-
return "cancer";
60-
} elseif (($month == 7 && $day >= 23) || ($month == 8 && $day <= 23)) {
61-
return "leo";
62-
} elseif (($month == 8 && $day >= 24) || ($month == 9 && $day <= 23)) {
63-
return "virgo";
64-
} elseif (($month == 9 && $day >= 24) || ($month == 10 && $day <= 23)) {
65-
return "libra";
66-
} elseif (($month == 10 && $day >= 24) || ($month == 11 && $day <= 22)) {
67-
return "scorpio";
68-
} elseif (($month == 11 && $day >= 23) || ($month == 12 && $day <= 21)) {
69-
return "sagittarius";
46+
return 'capricorn';
47+
}
48+
if (($month == 1 && $day >= 21) || ($month == 2 && $day <= 18)) {
49+
return 'aquarius';
50+
}
51+
if (($month == 2 && $day >= 19) || ($month == 3 && $day <= 20)) {
52+
return 'pisces';
53+
}
54+
if (($month == 3 && $day >= 21) || ($month == 4 && $day <= 20)) {
55+
return 'aries';
56+
}
57+
if (($month == 4 && $day >= 21) || ($month == 5 && $day <= 20)) {
58+
return 'taurus';
59+
}
60+
if (($month == 5 && $day >= 21) || ($month == 6 && $day <= 20)) {
61+
return 'gemini';
62+
}
63+
if (($month == 6 && $day >= 22) || ($month == 7 && $day <= 22)) {
64+
return 'cancer';
65+
}
66+
if (($month == 7 && $day >= 23) || ($month == 8 && $day <= 23)) {
67+
return 'leo';
68+
}
69+
if (($month == 8 && $day >= 24) || ($month == 9 && $day <= 23)) {
70+
return 'virgo';
71+
}
72+
if (($month == 9 && $day >= 24) || ($month == 10 && $day <= 23)) {
73+
return 'libra';
74+
}
75+
if (($month == 10 && $day >= 24) || ($month == 11 && $day <= 22)) {
76+
return 'scorpio';
77+
}
78+
if (($month == 11 && $day >= 23) || ($month == 12 && $day <= 21)) {
79+
return 'sagittarius';
7080
}
71-
};
81+
}
7282

73-
//! [class]
74-
//! [declaration]
7583
class AstrologyFlowElement extends FlowElement
7684
{
77-
//! [declaration]
78-
7985
// datakey used to categorise data coming back from this
8086
// FlowElement in a Pipeline
81-
public $dataKey = "astrology";
87+
public $dataKey = 'astrology';
88+
89+
public $properties = [
90+
'starSign' => [
91+
'type' => 'string',
92+
'description' => "the user's starsign"
93+
],
94+
'hemisphere' => [
95+
'type' => 'string',
96+
'description' => "the user's hemisphere"
97+
],
98+
'getLatitude' => [
99+
'type' => 'javascript',
100+
'description' => "JavaScript used to get a user's latitude"
101+
]
102+
];
82103

83104
// The processInternal function is the core working of a FlowElement.
84105
// It takes FlowData, reads evidence and returns data.
85-
public function processInternal($FlowData)
106+
public function processInternal($flowData)
86107
{
87108
$result = [];
88109

89-
90110
// Get the date of birth from the query string (submitted through
91111
// a form on the client side)
92-
$dateOfBirth = $FlowData->evidence->get("query.dateOfBirth");
112+
$dateOfBirth = $flowData->evidence->get('query.dateOfBirth');
93113

94114
if ($dateOfBirth) {
95-
$dateOfBirth = explode("-", $dateOfBirth);
115+
$dateOfBirth = explode('-', $dateOfBirth);
96116

97117
$month = $dateOfBirth[1];
98118
$day = $dateOfBirth[2];
99119

100-
101-
$result["starSign"] = getStarSign($month, $day);
120+
$result['starSign'] = getStarSign($month, $day);
102121
}
103122

104123
// Serve some JavaScript to the user that will be used to save
105124
// a cookie with the user's latitude in it
106-
$result["getLatitude"] = "navigator.geolocation.getCurrentPosition(function(position) {
107-
document.cookie = \"latitude=\" + position.coords.latitude;
125+
$result['getLatitude'] = 'navigator.geolocation.getCurrentPosition(function(position) {
126+
document.cookie = "latitude=" + position.coords.latitude;
108127
loadHemisphere();
109-
});";
128+
});';
110129

111130
// Get the latitude from the above cookie
112-
$latitude = $FlowData->evidence->get("cookie.latitude");
131+
$latitude = $flowData->evidence->get('cookie.latitude');
113132

114133
// Calculate the hemisphere
115134
if ($latitude) {
116-
$result["hemisphere"] = $latitude > 0 ? "Northern" : "Southern";
135+
$result['hemisphere'] = $latitude > 0 ? 'Northern' : 'Southern';
117136
}
118137

119-
120138
$data = new ElementDataDictionary($this, $result);
121139

122-
$FlowData->setElementData($data);
140+
$flowData->setElementData($data);
123141
}
124142

125-
public $properties = array(
126-
"starSign" => array(
127-
"type" => "string",
128-
"description" => "the user's starsign"
129-
),
130-
"hemisphere" => array(
131-
"type" => "string",
132-
"description" => "the user's hemisphere"
133-
),
134-
"getLatitude" => array(
135-
"type" => "javascript",
136-
"description" => "JavaScript used to get a user's latitude"
137-
)
138-
);
139-
140143
public function getEvidenceKeyFilter()
141144
{
142-
143145
// A filter (in this case a basic list) stating which evidence
144146
// the FlowElement is interested in
145-
return new BasicListEvidenceKeyFilter(["cookie.latitude", "query.dateOfBirth"]);
147+
return new BasicListEvidenceKeyFilter(['cookie.latitude', 'query.dateOfBirth']);
146148
}
147149
}
148150

149-
//! [class]
150-
//! [usage]
151-
152-
// Add some callback settings for the page to make a request with extra evidence from the client side, in this case the same url with an extra query string.
153-
154-
$javascriptBuilderSettings = array(
155-
"host" => "localhost:3000",
156-
"protocol" => "http",
157-
"endpoint" => "/?json"
158-
);
151+
// Add some callback settings for the page to make a request with extra evidence from the client side
152+
// in this case the same url with an extra query string.
153+
$javascriptBuilderSettings = [
154+
'host' => 'localhost:3000',
155+
'protocol' => 'http',
156+
'endpoint' => '/?json'
157+
];
159158

160159
// Make the Pipeline and add the element we want to it
160+
$Pipeline = (new PipelineBuilder(['javascriptBuilderSettings' => $javascriptBuilderSettings]))
161+
->add(new AstrologyFlowElement())
162+
->build();
161163

162-
$Pipeline = (new PipelineBuilder(["javascriptBuilderSettings"=>$javascriptBuilderSettings]))->add(new AstrologyFlowElement())->build();
163-
164-
$FlowData = $Pipeline->createFlowData();
164+
$flowData = $Pipeline->createFlowData();
165165

166166
// Add any information from the request (headers, cookies and additional
167167
// client side provided information)
168-
169-
$FlowData->evidence->setFromWebRequest();
168+
$flowData->evidence->setFromWebRequest();
170169

171170
// Process the FlowData
172-
173-
$FlowData->process();
171+
$flowData->process();
174172

175173
// The client side JavaScript calls back to this page
176174

177-
if (isset($_GET["json"])) {
178-
header("Content-Type: application/json; charset=UTF-8");
179-
echo json_encode($FlowData->jsonbundler->json);
175+
if (isset($_GET['json'])) {
176+
header('Content-Type: application/json; charset=UTF-8');
177+
echo json_encode($flowData->jsonbundler->json);
180178

181179
return;
182180
}
183181

184182
// Generate the HTML for the form that gets a user's starsign
183+
$output = '';
185184

186-
$output = "";
187-
188-
$output .= "<h1>Starsign</h1>";
189-
185+
$output .= '<h1>Starsign</h1>';
190186
$output .= "<form><label for='dateOfBirth'>Date of birth</label><input type='date' name='dateOfBirth' id='dateOfBirth'><input type='submit'></form>";
191187

192188
// Add the results if they're available
193-
194-
195-
if ($FlowData->astrology->starSign) {
196-
$output .= "<p>Your starsign is " . $FlowData->astrology->starSign . "</p>";
189+
if ($flowData->astrology->starSign) {
190+
$output .= '<p>Your starsign is ' . $flowData->astrology->starSign . '</p>';
197191
}
198192

199193
$output .= "<div id='hemispheretext'>";
200194

201-
if ($FlowData->astrology->hemisphere) {
202-
$output .= "<p>Look at the " . $FlowData->astrology->hemisphere . " hemisphere stars tonight!</p>";
195+
if ($flowData->astrology->hemisphere) {
196+
$output .= '<p>Look at the ' . $flowData->astrology->hemisphere . ' hemisphere stars tonight!</p>';
203197
}
204198

205-
$output .= "</div>";
206-
207-
$output .= "<script>";
199+
$output .= '</div>';
200+
$output .= '<script>';
208201

209202
// This function will fire when the JSON data object is updated
210203
// with information from the server.
@@ -214,7 +207,7 @@ public function getEvidenceKeyFilter()
214207
// 3. The web server responds with new JSON data that contains the hemisphere based on the location.
215208
// 4. The JavaScript integrates the new JSON data and fires the onChange callback below.
216209

217-
$output .= $FlowData->javascriptbuilder->javascript;
210+
$output .= $flowData->javascriptbuilder->javascript;
218211

219212
$output .= 'loadHemisphere = function() {
220213
fod.complete(function (data) {
@@ -234,9 +227,7 @@ public function getEvidenceKeyFilter()
234227
}
235228
})};';
236229

237-
$output .= "</script>";
230+
$output .= '</script>';
238231

239232
// Return the full output to the page
240-
241233
echo $output;
242-
//! [usage]

0 commit comments

Comments
 (0)