@@ -10,40 +10,40 @@ discard block |
||
10 | 10 | * @package Spyc |
11 | 11 | */ |
12 | 12 | |
13 | -if (!function_exists('spyc_load')) { |
|
13 | +if ( ! function_exists('spyc_load')) { |
|
14 | 14 | /** |
15 | 15 | * Parses YAML to array. |
16 | 16 | * @param string $string YAML string. |
17 | 17 | * @return array |
18 | 18 | */ |
19 | - function spyc_load ($string) { |
|
19 | + function spyc_load($string) { |
|
20 | 20 | return Spyc::YAMLLoadString($string); |
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | -if (!function_exists('spyc_load_file')) { |
|
24 | +if ( ! function_exists('spyc_load_file')) { |
|
25 | 25 | /** |
26 | 26 | * Parses YAML to array. |
27 | 27 | * @param string $file Path to YAML file. |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - function spyc_load_file ($file) { |
|
30 | + function spyc_load_file($file) { |
|
31 | 31 | return Spyc::YAMLLoad($file); |
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
35 | -if (!function_exists('spyc_dump')) { |
|
35 | +if ( ! function_exists('spyc_dump')) { |
|
36 | 36 | /** |
37 | 37 | * Dumps array to YAML. |
38 | 38 | * @param array $data Array. |
39 | 39 | * @return string |
40 | 40 | */ |
41 | - function spyc_dump ($data) { |
|
41 | + function spyc_dump($data) { |
|
42 | 42 | return Spyc::YAMLDump($data, false, false, true); |
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | -if (!class_exists('Spyc')) { |
|
46 | +if ( ! class_exists('Spyc')) { |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * The Simple PHP YAML Class. |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @param string $input |
121 | 121 | * @return array |
122 | 122 | */ |
123 | - public function load ($input) { |
|
123 | + public function load($input) { |
|
124 | 124 | return $this->__loadString($input); |
125 | 125 | } |
126 | 126 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @param string $file |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function loadFile ($file) { |
|
132 | + public function loadFile($file) { |
|
133 | 133 | return $this->__load($file); |
134 | 134 | } |
135 | 135 | |
@@ -224,18 +224,18 @@ discard block |
||
224 | 224 | * @param int $indent Pass in false to use the default, which is 2 |
225 | 225 | * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40) |
226 | 226 | */ |
227 | - public function dump($array,$indent = false,$wordwrap = false, $no_opening_dashes = false) { |
|
227 | + public function dump($array, $indent = false, $wordwrap = false, $no_opening_dashes = false) { |
|
228 | 228 | // Dumps to some very clean YAML. We'll have to add some more features |
229 | 229 | // and options soon. And better support for folding. |
230 | 230 | |
231 | 231 | // New features and options. |
232 | - if ($indent === false or !is_numeric($indent)) { |
|
232 | + if ($indent === false or ! is_numeric($indent)) { |
|
233 | 233 | $this->_dumpIndent = 2; |
234 | 234 | } else { |
235 | 235 | $this->_dumpIndent = $indent; |
236 | 236 | } |
237 | 237 | |
238 | - if ($wordwrap === false or !is_numeric($wordwrap)) { |
|
238 | + if ($wordwrap === false or ! is_numeric($wordwrap)) { |
|
239 | 239 | $this->_dumpWordWrap = 40; |
240 | 240 | } else { |
241 | 241 | $this->_dumpWordWrap = $wordwrap; |
@@ -243,15 +243,15 @@ discard block |
||
243 | 243 | |
244 | 244 | // New YAML document |
245 | 245 | $string = ""; |
246 | - if (!$no_opening_dashes) $string = "---\n"; |
|
246 | + if ( ! $no_opening_dashes) $string = "---\n"; |
|
247 | 247 | |
248 | 248 | // Start at the base of the array and move through it. |
249 | 249 | if ($array) { |
250 | - $array = (array)$array; |
|
250 | + $array = (array) $array; |
|
251 | 251 | $previous_key = -1; |
252 | 252 | foreach ($array as $key => $value) { |
253 | - if (!isset($first_key)) $first_key = $key; |
|
254 | - $string .= $this->_yamlize($key,$value,0,$previous_key, $first_key, $array); |
|
253 | + if ( ! isset($first_key)) $first_key = $key; |
|
254 | + $string .= $this->_yamlize($key, $value, 0, $previous_key, $first_key, $array); |
|
255 | 255 | $previous_key = $key; |
256 | 256 | } |
257 | 257 | } |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | * @param $value The value of the item |
267 | 267 | * @param $indent The indent of the current node |
268 | 268 | */ |
269 | - private function _yamlize($key,$value,$indent, $previous_key = -1, $first_key = 0, $source_array = null) { |
|
270 | - if(is_object($value)) $value = (array)$value; |
|
269 | + private function _yamlize($key, $value, $indent, $previous_key = -1, $first_key = 0, $source_array = null) { |
|
270 | + if (is_object($value)) $value = (array) $value; |
|
271 | 271 | if (is_array($value)) { |
272 | 272 | if (empty ($value)) |
273 | 273 | return $this->_dumpNode($key, array(), $indent, $previous_key, $first_key, $source_array); |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | // Add the indent |
278 | 278 | $indent += $this->_dumpIndent; |
279 | 279 | // Yamlize the array |
280 | - $string .= $this->_yamlizeArray($value,$indent); |
|
281 | - } elseif (!is_array($value)) { |
|
280 | + $string .= $this->_yamlizeArray($value, $indent); |
|
281 | + } elseif ( ! is_array($value)) { |
|
282 | 282 | // It doesn't have children. Yip. |
283 | 283 | $string = $this->_dumpNode($key, $value, $indent, $previous_key, $first_key, $source_array); |
284 | 284 | } |
@@ -292,12 +292,12 @@ discard block |
||
292 | 292 | * @param $array The array you want to convert |
293 | 293 | * @param $indent The indent of the current level |
294 | 294 | */ |
295 | - private function _yamlizeArray($array,$indent) { |
|
295 | + private function _yamlizeArray($array, $indent) { |
|
296 | 296 | if (is_array($array)) { |
297 | 297 | $string = ''; |
298 | 298 | $previous_key = -1; |
299 | 299 | foreach ($array as $key => $value) { |
300 | - if (!isset($first_key)) $first_key = $key; |
|
300 | + if ( ! isset($first_key)) $first_key = $key; |
|
301 | 301 | $string .= $this->_yamlize($key, $value, $indent, $previous_key, $first_key, $array); |
302 | 302 | $previous_key = $key; |
303 | 303 | } |
@@ -317,14 +317,14 @@ discard block |
||
317 | 317 | */ |
318 | 318 | private function _dumpNode($key, $value, $indent, $previous_key = -1, $first_key = 0, $source_array = null) { |
319 | 319 | // do some folding here, for blocks |
320 | - if (is_string ($value) && ((strpos($value,"\n") !== false || strpos($value,": ") !== false || strpos($value,"- ") !== false || |
|
321 | - strpos($value,"*") !== false || strpos($value,"#") !== false || strpos($value,"<") !== false || strpos($value,">") !== false || strpos ($value, '%') !== false || strpos ($value, ' ') !== false || |
|
322 | - strpos($value,"[") !== false || strpos($value,"]") !== false || strpos($value,"{") !== false || strpos($value,"}") !== false) || strpos($value,"&") !== false || strpos($value, "'") !== false || strpos($value, "!") === 0 || |
|
323 | - substr ($value, -1, 1) == ':') |
|
320 | + if (is_string($value) && ((strpos($value, "\n") !== false || strpos($value, ": ") !== false || strpos($value, "- ") !== false || |
|
321 | + strpos($value, "*") !== false || strpos($value, "#") !== false || strpos($value, "<") !== false || strpos($value, ">") !== false || strpos($value, '%') !== false || strpos($value, ' ') !== false || |
|
322 | + strpos($value, "[") !== false || strpos($value, "]") !== false || strpos($value, "{") !== false || strpos($value, "}") !== false) || strpos($value, "&") !== false || strpos($value, "'") !== false || strpos($value, "!") === 0 || |
|
323 | + substr($value, -1, 1) == ':') |
|
324 | 324 | ) { |
325 | - $value = $this->_doLiteralBlock($value,$indent); |
|
325 | + $value = $this->_doLiteralBlock($value, $indent); |
|
326 | 326 | } else { |
327 | - $value = $this->_doFolding($value,$indent); |
|
327 | + $value = $this->_doFolding($value, $indent); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | if ($value === array()) $value = '[ ]'; |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | if (self::isTranslationWord($value)) { |
333 | 333 | $value = $this->_doLiteralBlock($value, $indent); |
334 | 334 | } |
335 | - if (trim ($value) != $value) |
|
336 | - $value = $this->_doLiteralBlock($value,$indent); |
|
335 | + if (trim($value) != $value) |
|
336 | + $value = $this->_doLiteralBlock($value, $indent); |
|
337 | 337 | |
338 | 338 | if (is_bool($value)) { |
339 | 339 | $value = $value ? "true" : "false"; |
@@ -342,17 +342,17 @@ discard block |
||
342 | 342 | if ($value === null) $value = 'null'; |
343 | 343 | if ($value === "'" . self::REMPTY . "'") $value = null; |
344 | 344 | |
345 | - $spaces = str_repeat(' ',$indent); |
|
345 | + $spaces = str_repeat(' ', $indent); |
|
346 | 346 | |
347 | 347 | //if (is_int($key) && $key - 1 == $previous_key && $first_key===0) { |
348 | - if (is_array ($source_array) && array_keys($source_array) === range(0, count($source_array) - 1)) { |
|
348 | + if (is_array($source_array) && array_keys($source_array) === range(0, count($source_array) - 1)) { |
|
349 | 349 | // It's a sequence |
350 | - $string = $spaces.'- '.$value."\n"; |
|
350 | + $string = $spaces . '- ' . $value . "\n"; |
|
351 | 351 | } else { |
352 | 352 | // if ($first_key===0) throw new Exception('Keys are all screwy. The first one was zero, now it\'s "'. $key .'"'); |
353 | 353 | // It's mapped |
354 | 354 | if (strpos($key, ":") !== false || strpos($key, "#") !== false) { $key = '"' . $key . '"'; } |
355 | - $string = rtrim ($spaces.$key.': '.$value)."\n"; |
|
355 | + $string = rtrim($spaces . $key . ': ' . $value) . "\n"; |
|
356 | 356 | } |
357 | 357 | return $string; |
358 | 358 | } |
@@ -364,25 +364,25 @@ discard block |
||
364 | 364 | * @param $value |
365 | 365 | * @param $indent int The value of the indent |
366 | 366 | */ |
367 | - private function _doLiteralBlock($value,$indent) { |
|
367 | + private function _doLiteralBlock($value, $indent) { |
|
368 | 368 | if ($value === "\n") return '\n'; |
369 | 369 | if (strpos($value, "\n") === false && strpos($value, "'") === false) { |
370 | - return sprintf ("'%s'", $value); |
|
370 | + return sprintf("'%s'", $value); |
|
371 | 371 | } |
372 | 372 | if (strpos($value, "\n") === false && strpos($value, '"') === false) { |
373 | - return sprintf ('"%s"', $value); |
|
373 | + return sprintf('"%s"', $value); |
|
374 | 374 | } |
375 | - $exploded = explode("\n",$value); |
|
375 | + $exploded = explode("\n", $value); |
|
376 | 376 | $newValue = '|'; |
377 | 377 | if (isset($exploded[0]) && ($exploded[0] == "|" || $exploded[0] == "|-" || $exploded[0] == ">")) { |
378 | 378 | $newValue = $exploded[0]; |
379 | 379 | unset($exploded[0]); |
380 | 380 | } |
381 | 381 | $indent += $this->_dumpIndent; |
382 | - $spaces = str_repeat(' ',$indent); |
|
382 | + $spaces = str_repeat(' ', $indent); |
|
383 | 383 | foreach ($exploded as $line) { |
384 | 384 | $line = trim($line); |
385 | - if (strpos($line, '"') === 0 && strrpos($line, '"') == (strlen($line)-1) || strpos($line, "'") === 0 && strrpos($line, "'") == (strlen($line)-1)) { |
|
385 | + if (strpos($line, '"') === 0 && strrpos($line, '"') == (strlen($line) - 1) || strpos($line, "'") === 0 && strrpos($line, "'") == (strlen($line) - 1)) { |
|
386 | 386 | $line = substr($line, 1, -1); |
387 | 387 | } |
388 | 388 | $newValue .= "\n" . $spaces . ($line); |
@@ -396,16 +396,16 @@ discard block |
||
396 | 396 | * @return string |
397 | 397 | * @param $value The string you wish to fold |
398 | 398 | */ |
399 | - private function _doFolding($value,$indent) { |
|
399 | + private function _doFolding($value, $indent) { |
|
400 | 400 | // Don't do anything if wordwrap is set to 0 |
401 | 401 | |
402 | - if ($this->_dumpWordWrap !== 0 && is_string ($value) && strlen($value) > $this->_dumpWordWrap) { |
|
402 | + if ($this->_dumpWordWrap !== 0 && is_string($value) && strlen($value) > $this->_dumpWordWrap) { |
|
403 | 403 | $indent += $this->_dumpIndent; |
404 | - $indent = str_repeat(' ',$indent); |
|
405 | - $wrapped = wordwrap($value,$this->_dumpWordWrap,"\n$indent"); |
|
406 | - $value = ">\n".$indent.$wrapped; |
|
404 | + $indent = str_repeat(' ', $indent); |
|
405 | + $wrapped = wordwrap($value, $this->_dumpWordWrap, "\n$indent"); |
|
406 | + $value = ">\n" . $indent . $wrapped; |
|
407 | 407 | } else { |
408 | - if ($this->setting_dump_force_quotes && is_string ($value) && $value !== self::REMPTY) |
|
408 | + if ($this->setting_dump_force_quotes && is_string($value) && $value !== self::REMPTY) |
|
409 | 409 | $value = '"' . $value . '"'; |
410 | 410 | if (is_numeric($value) && is_string($value)) |
411 | 411 | $value = '"' . $value . '"'; |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | |
433 | 433 | private function isTranslationWord($value) { |
434 | 434 | return ( |
435 | - self::isTrueWord($value) || |
|
435 | + self::isTrueWord($value) || |
|
436 | 436 | self::isFalseWord($value) || |
437 | 437 | self::isNullWord($value) |
438 | 438 | ); |
@@ -483,8 +483,8 @@ discard block |
||
483 | 483 | |
484 | 484 | private function loadWithSource($Source) { |
485 | 485 | if (empty ($Source)) return array(); |
486 | - if ($this->setting_use_syck_is_possible && function_exists ('syck_load')) { |
|
487 | - $array = syck_load (implode ("\n", $Source)); |
|
486 | + if ($this->setting_use_syck_is_possible && function_exists('syck_load')) { |
|
487 | + $array = syck_load(implode("\n", $Source)); |
|
488 | 488 | return is_array($array) ? $array : array(); |
489 | 489 | } |
490 | 490 | |
@@ -504,10 +504,10 @@ discard block |
||
504 | 504 | |
505 | 505 | $literalBlockStyle = self::startsLiteralBlock($line); |
506 | 506 | if ($literalBlockStyle) { |
507 | - $line = rtrim ($line, $literalBlockStyle . " \n"); |
|
507 | + $line = rtrim($line, $literalBlockStyle . " \n"); |
|
508 | 508 | $literalBlock = ''; |
509 | - $line .= ' '.$this->LiteralPlaceHolder; |
|
510 | - $literal_block_indent = strlen($Source[$i+1]) - strlen(ltrim($Source[$i+1])); |
|
509 | + $line .= ' ' . $this->LiteralPlaceHolder; |
|
510 | + $literal_block_indent = strlen($Source[$i + 1]) - strlen(ltrim($Source[$i + 1])); |
|
511 | 511 | while (++$i < $cnt && $this->literalBlockContinues($Source[$i], $this->indent)) { |
512 | 512 | $literalBlock = $this->addLiteralLine($literalBlock, $Source[$i], $literalBlockStyle, $literal_block_indent); |
513 | 513 | } |
@@ -515,19 +515,19 @@ discard block |
||
515 | 515 | } |
516 | 516 | |
517 | 517 | // Strip out comments |
518 | - if (strpos ($line, '#')) { |
|
519 | - $line = preg_replace('/\s*#([^"\']+)$/','',$line); |
|
518 | + if (strpos($line, '#')) { |
|
519 | + $line = preg_replace('/\s*#([^"\']+)$/', '', $line); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | while (++$i < $cnt && self::greedilyNeedNextLine($line)) { |
523 | - $line = rtrim ($line, " \n\t\r") . ' ' . ltrim ($Source[$i], " \t"); |
|
523 | + $line = rtrim($line, " \n\t\r") . ' ' . ltrim($Source[$i], " \t"); |
|
524 | 524 | } |
525 | 525 | $i--; |
526 | 526 | |
527 | 527 | $lineArray = $this->_parseLine($line); |
528 | 528 | |
529 | 529 | if ($literalBlockStyle) |
530 | - $lineArray = $this->revertLiteralPlaceHolder ($lineArray, $literalBlock); |
|
530 | + $lineArray = $this->revertLiteralPlaceHolder($lineArray, $literalBlock); |
|
531 | 531 | |
532 | 532 | $this->addArray($lineArray, $this->indent); |
533 | 533 | |
@@ -540,17 +540,17 @@ discard block |
||
540 | 540 | return $this->result; |
541 | 541 | } |
542 | 542 | |
543 | - private function loadFromSource ($input) { |
|
544 | - if (!empty($input) && strpos($input, "\n") === false && file_exists($input)) |
|
543 | + private function loadFromSource($input) { |
|
544 | + if ( ! empty($input) && strpos($input, "\n") === false && file_exists($input)) |
|
545 | 545 | $input = file_get_contents($input); |
546 | 546 | |
547 | 547 | return $this->loadFromString($input); |
548 | 548 | } |
549 | 549 | |
550 | - private function loadFromString ($input) { |
|
551 | - $lines = explode("\n",$input); |
|
550 | + private function loadFromString($input) { |
|
551 | + $lines = explode("\n", $input); |
|
552 | 552 | foreach ($lines as $k => $_) { |
553 | - $lines[$k] = rtrim ($_, "\r"); |
|
553 | + $lines[$k] = rtrim($_, "\r"); |
|
554 | 554 | } |
555 | 555 | return $lines; |
556 | 556 | } |
@@ -562,16 +562,16 @@ discard block |
||
562 | 562 | * @param string $line A line from the YAML file |
563 | 563 | */ |
564 | 564 | private function _parseLine($line) { |
565 | - if (!$line) return array(); |
|
565 | + if ( ! $line) return array(); |
|
566 | 566 | $line = trim($line); |
567 | - if (!$line) return array(); |
|
567 | + if ( ! $line) return array(); |
|
568 | 568 | |
569 | 569 | $array = array(); |
570 | 570 | |
571 | 571 | $group = $this->nodeContainsGroup($line); |
572 | 572 | if ($group) { |
573 | 573 | $this->addGroup($line, $group); |
574 | - $line = $this->stripGroup ($line, $group); |
|
574 | + $line = $this->stripGroup($line, $group); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | if ($this->startsMappedSequence($line)) |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | |
605 | 605 | $is_quoted = false; |
606 | 606 | do { |
607 | - if (!$value) break; |
|
607 | + if ( ! $value) break; |
|
608 | 608 | if ($first_character != '"' && $first_character != "'") break; |
609 | 609 | if ($last_character != '"' && $last_character != "'") break; |
610 | 610 | $is_quoted = true; |
@@ -613,37 +613,37 @@ discard block |
||
613 | 613 | if ($is_quoted) { |
614 | 614 | $value = str_replace('\n', "\n", $value); |
615 | 615 | if ($first_character == "'") |
616 | - return strtr(substr ($value, 1, -1), array ('\'\'' => '\'', '\\\''=> '\'')); |
|
617 | - return strtr(substr ($value, 1, -1), array ('\\"' => '"', '\\\''=> '\'')); |
|
616 | + return strtr(substr($value, 1, -1), array('\'\'' => '\'', '\\\''=> '\'')); |
|
617 | + return strtr(substr($value, 1, -1), array('\\"' => '"', '\\\''=> '\'')); |
|
618 | 618 | } |
619 | 619 | |
620 | - if (strpos($value, ' #') !== false && !$is_quoted) |
|
621 | - $value = preg_replace('/\s+#(.+)$/','',$value); |
|
620 | + if (strpos($value, ' #') !== false && ! $is_quoted) |
|
621 | + $value = preg_replace('/\s+#(.+)$/', '', $value); |
|
622 | 622 | |
623 | 623 | if ($first_character == '[' && $last_character == ']') { |
624 | 624 | // Take out strings sequences and mappings |
625 | - $innerValue = trim(substr ($value, 1, -1)); |
|
625 | + $innerValue = trim(substr($value, 1, -1)); |
|
626 | 626 | if ($innerValue === '') return array(); |
627 | 627 | $explode = $this->_inlineEscape($innerValue); |
628 | 628 | // Propagate value array |
629 | - $value = array(); |
|
629 | + $value = array(); |
|
630 | 630 | foreach ($explode as $v) { |
631 | 631 | $value[] = $this->_toType($v); |
632 | 632 | } |
633 | 633 | return $value; |
634 | 634 | } |
635 | 635 | |
636 | - if (strpos($value,': ')!==false && $first_character != '{') { |
|
637 | - $array = explode(': ',$value); |
|
636 | + if (strpos($value, ': ') !== false && $first_character != '{') { |
|
637 | + $array = explode(': ', $value); |
|
638 | 638 | $key = trim($array[0]); |
639 | 639 | array_shift($array); |
640 | - $value = trim(implode(': ',$array)); |
|
640 | + $value = trim(implode(': ', $array)); |
|
641 | 641 | $value = $this->_toType($value); |
642 | 642 | return array($key => $value); |
643 | 643 | } |
644 | 644 | |
645 | 645 | if ($first_character == '{' && $last_character == '}') { |
646 | - $innerValue = trim(substr ($value, 1, -1)); |
|
646 | + $innerValue = trim(substr($value, 1, -1)); |
|
647 | 647 | if ($innerValue === '') return array(); |
648 | 648 | // Inline Mapping |
649 | 649 | // Take out strings sequences and mappings |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | foreach ($explode as $v) { |
654 | 654 | $SubArr = $this->_toType($v); |
655 | 655 | if (empty($SubArr)) continue; |
656 | - if (is_array ($SubArr)) { |
|
656 | + if (is_array($SubArr)) { |
|
657 | 657 | $array[key($SubArr)] = $SubArr[key($SubArr)]; continue; |
658 | 658 | } |
659 | 659 | $array[] = $SubArr; |
@@ -665,8 +665,8 @@ discard block |
||
665 | 665 | return null; |
666 | 666 | } |
667 | 667 | |
668 | - if ( is_numeric($value) && preg_match ('/^(-|)[1-9]+[0-9]*$/', $value) ){ |
|
669 | - $intvalue = (int)$value; |
|
668 | + if (is_numeric($value) && preg_match('/^(-|)[1-9]+[0-9]*$/', $value)) { |
|
669 | + $intvalue = (int) $value; |
|
670 | 670 | if ($intvalue != PHP_INT_MAX && $intvalue != ~PHP_INT_MAX) |
671 | 671 | $value = $intvalue; |
672 | 672 | return $value; |
@@ -681,8 +681,8 @@ discard block |
||
681 | 681 | |
682 | 682 | if (is_numeric($value)) { |
683 | 683 | if ($value === '0') return 0; |
684 | - if (rtrim ($value, 0) === $value) |
|
685 | - $value = (float)$value; |
|
684 | + if (rtrim($value, 0) === $value) |
|
685 | + $value = (float) $value; |
|
686 | 686 | return $value; |
687 | 687 | } |
688 | 688 | |
@@ -707,17 +707,17 @@ discard block |
||
707 | 707 | |
708 | 708 | // Check for empty strings |
709 | 709 | $regex = '/("")|(\'\')/'; |
710 | - if (preg_match_all($regex,$inline,$strings)) { |
|
710 | + if (preg_match_all($regex, $inline, $strings)) { |
|
711 | 711 | $saved_empties = $strings[0]; |
712 | - $inline = preg_replace($regex,'YAMLEmpty',$inline); |
|
712 | + $inline = preg_replace($regex, 'YAMLEmpty', $inline); |
|
713 | 713 | } |
714 | 714 | unset($regex); |
715 | 715 | |
716 | 716 | // Check for strings |
717 | 717 | $regex = '/(?:(")|(?:\'))((?(1)[^"]+|[^\']+))(?(1)"|\')/'; |
718 | - if (preg_match_all($regex,$inline,$strings)) { |
|
718 | + if (preg_match_all($regex, $inline, $strings)) { |
|
719 | 719 | $saved_strings = $strings[0]; |
720 | - $inline = preg_replace($regex,'YAMLString',$inline); |
|
720 | + $inline = preg_replace($regex, 'YAMLString', $inline); |
|
721 | 721 | } |
722 | 722 | unset($regex); |
723 | 723 | |
@@ -727,33 +727,33 @@ discard block |
||
727 | 727 | do { |
728 | 728 | |
729 | 729 | // Check for sequences |
730 | - while (preg_match('/\[([^{}\[\]]+)\]/U',$inline,$matchseqs)) { |
|
730 | + while (preg_match('/\[([^{}\[\]]+)\]/U', $inline, $matchseqs)) { |
|
731 | 731 | $seqs[] = $matchseqs[0]; |
732 | 732 | $inline = preg_replace('/\[([^{}\[\]]+)\]/U', ('YAMLSeq' . (count($seqs) - 1) . 's'), $inline, 1); |
733 | 733 | } |
734 | 734 | |
735 | 735 | // Check for mappings |
736 | - while (preg_match('/{([^\[\]{}]+)}/U',$inline,$matchmaps)) { |
|
736 | + while (preg_match('/{([^\[\]{}]+)}/U', $inline, $matchmaps)) { |
|
737 | 737 | $maps[] = $matchmaps[0]; |
738 | 738 | $inline = preg_replace('/{([^\[\]{}]+)}/U', ('YAMLMap' . (count($maps) - 1) . 's'), $inline, 1); |
739 | 739 | } |
740 | 740 | |
741 | 741 | if ($i++ >= 10) break; |
742 | 742 | |
743 | - } while (strpos ($inline, '[') !== false || strpos ($inline, '{') !== false); |
|
743 | + } while (strpos($inline, '[') !== false || strpos($inline, '{') !== false); |
|
744 | 744 | |
745 | - $explode = explode(',',$inline); |
|
745 | + $explode = explode(',', $inline); |
|
746 | 746 | $explode = array_map('trim', $explode); |
747 | 747 | $stringi = 0; $i = 0; |
748 | 748 | |
749 | 749 | while (1) { |
750 | 750 | |
751 | 751 | // Re-add the sequences |
752 | - if (!empty($seqs)) { |
|
752 | + if ( ! empty($seqs)) { |
|
753 | 753 | foreach ($explode as $key => $value) { |
754 | - if (strpos($value,'YAMLSeq') !== false) { |
|
754 | + if (strpos($value, 'YAMLSeq') !== false) { |
|
755 | 755 | foreach ($seqs as $seqk => $seq) { |
756 | - $explode[$key] = str_replace(('YAMLSeq'.$seqk.'s'),$seq,$value); |
|
756 | + $explode[$key] = str_replace(('YAMLSeq' . $seqk . 's'), $seq, $value); |
|
757 | 757 | $value = $explode[$key]; |
758 | 758 | } |
759 | 759 | } |
@@ -761,11 +761,11 @@ discard block |
||
761 | 761 | } |
762 | 762 | |
763 | 763 | // Re-add the mappings |
764 | - if (!empty($maps)) { |
|
764 | + if ( ! empty($maps)) { |
|
765 | 765 | foreach ($explode as $key => $value) { |
766 | - if (strpos($value,'YAMLMap') !== false) { |
|
766 | + if (strpos($value, 'YAMLMap') !== false) { |
|
767 | 767 | foreach ($maps as $mapk => $map) { |
768 | - $explode[$key] = str_replace(('YAMLMap'.$mapk.'s'), $map, $value); |
|
768 | + $explode[$key] = str_replace(('YAMLMap' . $mapk . 's'), $map, $value); |
|
769 | 769 | $value = $explode[$key]; |
770 | 770 | } |
771 | 771 | } |
@@ -774,10 +774,10 @@ discard block |
||
774 | 774 | |
775 | 775 | |
776 | 776 | // Re-add the strings |
777 | - if (!empty($saved_strings)) { |
|
777 | + if ( ! empty($saved_strings)) { |
|
778 | 778 | foreach ($explode as $key => $value) { |
779 | - while (strpos($value,'YAMLString') !== false) { |
|
780 | - $explode[$key] = preg_replace('/YAMLString/',$saved_strings[$stringi],$value, 1); |
|
779 | + while (strpos($value, 'YAMLString') !== false) { |
|
780 | + $explode[$key] = preg_replace('/YAMLString/', $saved_strings[$stringi], $value, 1); |
|
781 | 781 | unset($saved_strings[$stringi]); |
782 | 782 | ++$stringi; |
783 | 783 | $value = $explode[$key]; |
@@ -787,9 +787,9 @@ discard block |
||
787 | 787 | |
788 | 788 | |
789 | 789 | // Re-add the empties |
790 | - if (!empty($saved_empties)) { |
|
790 | + if ( ! empty($saved_empties)) { |
|
791 | 791 | foreach ($explode as $key => $value) { |
792 | - while (strpos($value,'YAMLEmpty') !== false) { |
|
792 | + while (strpos($value, 'YAMLEmpty') !== false) { |
|
793 | 793 | $explode[$key] = preg_replace('/YAMLEmpty/', '', $value, 1); |
794 | 794 | $value = $explode[$key]; |
795 | 795 | } |
@@ -798,16 +798,16 @@ discard block |
||
798 | 798 | |
799 | 799 | $finished = true; |
800 | 800 | foreach ($explode as $key => $value) { |
801 | - if (strpos($value,'YAMLSeq') !== false) { |
|
801 | + if (strpos($value, 'YAMLSeq') !== false) { |
|
802 | 802 | $finished = false; break; |
803 | 803 | } |
804 | - if (strpos($value,'YAMLMap') !== false) { |
|
804 | + if (strpos($value, 'YAMLMap') !== false) { |
|
805 | 805 | $finished = false; break; |
806 | 806 | } |
807 | - if (strpos($value,'YAMLString') !== false) { |
|
807 | + if (strpos($value, 'YAMLString') !== false) { |
|
808 | 808 | $finished = false; break; |
809 | 809 | } |
810 | - if (strpos($value,'YAMLEmpty') !== false) { |
|
810 | + if (strpos($value, 'YAMLEmpty') !== false) { |
|
811 | 811 | $finished = false; break; |
812 | 812 | } |
813 | 813 | } |
@@ -822,15 +822,15 @@ discard block |
||
822 | 822 | return $explode; |
823 | 823 | } |
824 | 824 | |
825 | - private function literalBlockContinues ($line, $lineIndent) { |
|
826 | - if (!trim($line)) return true; |
|
825 | + private function literalBlockContinues($line, $lineIndent) { |
|
826 | + if ( ! trim($line)) return true; |
|
827 | 827 | if (strlen($line) - strlen(ltrim($line)) > $lineIndent) return true; |
828 | 828 | return false; |
829 | 829 | } |
830 | 830 | |
831 | - private function referenceContentsByAlias ($alias) { |
|
831 | + private function referenceContentsByAlias($alias) { |
|
832 | 832 | do { |
833 | - if (!isset($this->SavedGroups[$alias])) { echo "Bad group name: $alias."; break; } |
|
833 | + if ( ! isset($this->SavedGroups[$alias])) { echo "Bad group name: $alias."; break; } |
|
834 | 834 | $groupPath = $this->SavedGroups[$alias]; |
835 | 835 | $value = $this->result; |
836 | 836 | foreach ($groupPath as $k) { |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | return $value; |
841 | 841 | } |
842 | 842 | |
843 | - private function addArrayInline ($array, $indent) { |
|
843 | + private function addArrayInline($array, $indent) { |
|
844 | 844 | $CommonGroupPath = $this->path; |
845 | 845 | if (empty ($array)) return false; |
846 | 846 | |
@@ -851,22 +851,22 @@ discard block |
||
851 | 851 | return true; |
852 | 852 | } |
853 | 853 | |
854 | - private function addArray ($incoming_data, $incoming_indent) { |
|
854 | + private function addArray($incoming_data, $incoming_indent) { |
|
855 | 855 | |
856 | 856 | // print_r ($incoming_data); |
857 | 857 | |
858 | - if (count ($incoming_data) > 1) |
|
859 | - return $this->addArrayInline ($incoming_data, $incoming_indent); |
|
858 | + if (count($incoming_data) > 1) |
|
859 | + return $this->addArrayInline($incoming_data, $incoming_indent); |
|
860 | 860 | |
861 | - $key = key ($incoming_data); |
|
861 | + $key = key($incoming_data); |
|
862 | 862 | $value = isset($incoming_data[$key]) ? $incoming_data[$key] : null; |
863 | 863 | if ($key === '__!YAMLZero') $key = '0'; |
864 | 864 | |
865 | - if ($incoming_indent == 0 && !$this->_containsGroupAlias && !$this->_containsGroupAnchor) { // Shortcut for root-level values. |
|
865 | + if ($incoming_indent == 0 && ! $this->_containsGroupAlias && ! $this->_containsGroupAnchor) { // Shortcut for root-level values. |
|
866 | 866 | if ($key || $key === '' || $key === '0') { |
867 | 867 | $this->result[$key] = $value; |
868 | 868 | } else { |
869 | - $this->result[] = $value; end ($this->result); $key = key ($this->result); |
|
869 | + $this->result[] = $value; end($this->result); $key = key($this->result); |
|
870 | 870 | } |
871 | 871 | $this->path[$incoming_indent] = $key; |
872 | 872 | return; |
@@ -889,25 +889,25 @@ discard block |
||
889 | 889 | |
890 | 890 | // Adding string or numeric key to the innermost level or $this->arr. |
891 | 891 | if (is_string($key) && $key == '<<') { |
892 | - if (!is_array ($_arr)) { $_arr = array (); } |
|
892 | + if ( ! is_array($_arr)) { $_arr = array(); } |
|
893 | 893 | |
894 | - $_arr = array_merge ($_arr, $value); |
|
894 | + $_arr = array_merge($_arr, $value); |
|
895 | 895 | } else if ($key || $key === '' || $key === '0') { |
896 | - if (!is_array ($_arr)) |
|
897 | - $_arr = array ($key=>$value); |
|
896 | + if ( ! is_array($_arr)) |
|
897 | + $_arr = array($key=>$value); |
|
898 | 898 | else |
899 | 899 | $_arr[$key] = $value; |
900 | 900 | } else { |
901 | - if (!is_array ($_arr)) { $_arr = array ($value); $key = 0; } |
|
902 | - else { $_arr[] = $value; end ($_arr); $key = key ($_arr); } |
|
901 | + if ( ! is_array($_arr)) { $_arr = array($value); $key = 0; } |
|
902 | + else { $_arr[] = $value; end($_arr); $key = key($_arr); } |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | $reverse_path = array_reverse($this->path); |
906 | - $reverse_history = array_reverse ($history); |
|
906 | + $reverse_history = array_reverse($history); |
|
907 | 907 | $reverse_history[0] = $_arr; |
908 | 908 | $cnt = count($reverse_history) - 1; |
909 | 909 | for ($i = 0; $i < $cnt; $i++) { |
910 | - $reverse_history[$i+1][$reverse_path[$i]] = $reverse_history[$i]; |
|
910 | + $reverse_history[$i + 1][$reverse_path[$i]] = $reverse_history[$i]; |
|
911 | 911 | } |
912 | 912 | $this->result = $reverse_history[$cnt]; |
913 | 913 | |
@@ -915,9 +915,9 @@ discard block |
||
915 | 915 | |
916 | 916 | if ($this->_containsGroupAnchor) { |
917 | 917 | $this->SavedGroups[$this->_containsGroupAnchor] = $this->path; |
918 | - if (is_array ($value)) { |
|
919 | - $k = key ($value); |
|
920 | - if (!is_int ($k)) { |
|
918 | + if (is_array($value)) { |
|
919 | + $k = key($value); |
|
920 | + if ( ! is_int($k)) { |
|
921 | 921 | $this->SavedGroups[$this->_containsGroupAnchor][$incoming_indent + 2] = $k; |
922 | 922 | } |
923 | 923 | } |
@@ -926,70 +926,70 @@ discard block |
||
926 | 926 | |
927 | 927 | } |
928 | 928 | |
929 | - private static function startsLiteralBlock ($line) { |
|
930 | - $lastChar = substr (trim($line), -1); |
|
929 | + private static function startsLiteralBlock($line) { |
|
930 | + $lastChar = substr(trim($line), -1); |
|
931 | 931 | if ($lastChar != '>' && $lastChar != '|') return false; |
932 | 932 | if ($lastChar == '|') return $lastChar; |
933 | 933 | // HTML tags should not be counted as literal blocks. |
934 | - if (preg_match ('#<.*?>$#', $line)) return false; |
|
934 | + if (preg_match('#<.*?>$#', $line)) return false; |
|
935 | 935 | return $lastChar; |
936 | 936 | } |
937 | 937 | |
938 | 938 | private static function greedilyNeedNextLine($line) { |
939 | - $line = trim ($line); |
|
940 | - if (!strlen($line)) return false; |
|
941 | - if (substr ($line, -1, 1) == ']') return false; |
|
939 | + $line = trim($line); |
|
940 | + if ( ! strlen($line)) return false; |
|
941 | + if (substr($line, -1, 1) == ']') return false; |
|
942 | 942 | if ($line[0] == '[') return true; |
943 | - if (preg_match ('#^[^:]+?:\s*\[#', $line)) return true; |
|
943 | + if (preg_match('#^[^:]+?:\s*\[#', $line)) return true; |
|
944 | 944 | return false; |
945 | 945 | } |
946 | 946 | |
947 | - private function addLiteralLine ($literalBlock, $line, $literalBlockStyle, $indent = -1) { |
|
947 | + private function addLiteralLine($literalBlock, $line, $literalBlockStyle, $indent = -1) { |
|
948 | 948 | $line = self::stripIndent($line, $indent); |
949 | 949 | if ($literalBlockStyle !== '|') { |
950 | 950 | $line = self::stripIndent($line); |
951 | 951 | } |
952 | - $line = rtrim ($line, "\r\n\t ") . "\n"; |
|
952 | + $line = rtrim($line, "\r\n\t ") . "\n"; |
|
953 | 953 | if ($literalBlockStyle == '|') { |
954 | 954 | return $literalBlock . $line; |
955 | 955 | } |
956 | 956 | if (strlen($line) == 0) |
957 | 957 | return rtrim($literalBlock, ' ') . "\n"; |
958 | 958 | if ($line == "\n" && $literalBlockStyle == '>') { |
959 | - return rtrim ($literalBlock, " \t") . "\n"; |
|
959 | + return rtrim($literalBlock, " \t") . "\n"; |
|
960 | 960 | } |
961 | 961 | if ($line != "\n") |
962 | - $line = trim ($line, "\r\n ") . " "; |
|
962 | + $line = trim($line, "\r\n ") . " "; |
|
963 | 963 | return $literalBlock . $line; |
964 | 964 | } |
965 | 965 | |
966 | - function revertLiteralPlaceHolder ($lineArray, $literalBlock) { |
|
966 | + function revertLiteralPlaceHolder($lineArray, $literalBlock) { |
|
967 | 967 | foreach ($lineArray as $k => $_) { |
968 | 968 | if (is_array($_)) |
969 | - $lineArray[$k] = $this->revertLiteralPlaceHolder ($_, $literalBlock); |
|
970 | - else if (substr($_, -1 * strlen ($this->LiteralPlaceHolder)) == $this->LiteralPlaceHolder) |
|
971 | - $lineArray[$k] = rtrim ($literalBlock, " \r\n"); |
|
969 | + $lineArray[$k] = $this->revertLiteralPlaceHolder($_, $literalBlock); |
|
970 | + else if (substr($_, -1 * strlen($this->LiteralPlaceHolder)) == $this->LiteralPlaceHolder) |
|
971 | + $lineArray[$k] = rtrim($literalBlock, " \r\n"); |
|
972 | 972 | } |
973 | 973 | return $lineArray; |
974 | 974 | } |
975 | 975 | |
976 | - private static function stripIndent ($line, $indent = -1) { |
|
976 | + private static function stripIndent($line, $indent = -1) { |
|
977 | 977 | if ($indent == -1) $indent = strlen($line) - strlen(ltrim($line)); |
978 | - return substr ($line, $indent); |
|
978 | + return substr($line, $indent); |
|
979 | 979 | } |
980 | 980 | |
981 | - private function getParentPathByIndent ($indent) { |
|
981 | + private function getParentPathByIndent($indent) { |
|
982 | 982 | if ($indent == 0) return array(); |
983 | 983 | $linePath = $this->path; |
984 | 984 | do { |
985 | 985 | end($linePath); $lastIndentInParentPath = key($linePath); |
986 | - if ($indent <= $lastIndentInParentPath) array_pop ($linePath); |
|
986 | + if ($indent <= $lastIndentInParentPath) array_pop($linePath); |
|
987 | 987 | } while ($indent <= $lastIndentInParentPath); |
988 | 988 | return $linePath; |
989 | 989 | } |
990 | 990 | |
991 | 991 | |
992 | - private function clearBiggerPathValues ($indent) { |
|
992 | + private function clearBiggerPathValues($indent) { |
|
993 | 993 | |
994 | 994 | |
995 | 995 | if ($indent == 0) $this->path = array(); |
@@ -1003,94 +1003,94 @@ discard block |
||
1003 | 1003 | } |
1004 | 1004 | |
1005 | 1005 | |
1006 | - private static function isComment ($line) { |
|
1007 | - if (!$line) return false; |
|
1006 | + private static function isComment($line) { |
|
1007 | + if ( ! $line) return false; |
|
1008 | 1008 | if ($line[0] == '#') return true; |
1009 | 1009 | if (trim($line, " \r\n\t") == '---') return true; |
1010 | 1010 | return false; |
1011 | 1011 | } |
1012 | 1012 | |
1013 | - private static function isEmpty ($line) { |
|
1014 | - return (trim ($line) === ''); |
|
1013 | + private static function isEmpty($line) { |
|
1014 | + return (trim($line) === ''); |
|
1015 | 1015 | } |
1016 | 1016 | |
1017 | 1017 | |
1018 | - private function isArrayElement ($line) { |
|
1019 | - if (!$line || !is_scalar($line)) return false; |
|
1018 | + private function isArrayElement($line) { |
|
1019 | + if ( ! $line || ! is_scalar($line)) return false; |
|
1020 | 1020 | if (substr($line, 0, 2) != '- ') return false; |
1021 | - if (strlen ($line) > 3) |
|
1022 | - if (substr($line,0,3) == '---') return false; |
|
1021 | + if (strlen($line) > 3) |
|
1022 | + if (substr($line, 0, 3) == '---') return false; |
|
1023 | 1023 | |
1024 | 1024 | return true; |
1025 | 1025 | } |
1026 | 1026 | |
1027 | - private function isHashElement ($line) { |
|
1027 | + private function isHashElement($line) { |
|
1028 | 1028 | return strpos($line, ':'); |
1029 | 1029 | } |
1030 | 1030 | |
1031 | - private function isLiteral ($line) { |
|
1031 | + private function isLiteral($line) { |
|
1032 | 1032 | if ($this->isArrayElement($line)) return false; |
1033 | 1033 | if ($this->isHashElement($line)) return false; |
1034 | 1034 | return true; |
1035 | 1035 | } |
1036 | 1036 | |
1037 | 1037 | |
1038 | - private static function unquote ($value) { |
|
1039 | - if (!$value) return $value; |
|
1040 | - if (!is_string($value)) return $value; |
|
1041 | - if ($value[0] == '\'') return trim ($value, '\''); |
|
1042 | - if ($value[0] == '"') return trim ($value, '"'); |
|
1038 | + private static function unquote($value) { |
|
1039 | + if ( ! $value) return $value; |
|
1040 | + if ( ! is_string($value)) return $value; |
|
1041 | + if ($value[0] == '\'') return trim($value, '\''); |
|
1042 | + if ($value[0] == '"') return trim($value, '"'); |
|
1043 | 1043 | return $value; |
1044 | 1044 | } |
1045 | 1045 | |
1046 | - private function startsMappedSequence ($line) { |
|
1047 | - return (substr($line, 0, 2) == '- ' && substr ($line, -1, 1) == ':'); |
|
1046 | + private function startsMappedSequence($line) { |
|
1047 | + return (substr($line, 0, 2) == '- ' && substr($line, -1, 1) == ':'); |
|
1048 | 1048 | } |
1049 | 1049 | |
1050 | - private function returnMappedSequence ($line) { |
|
1050 | + private function returnMappedSequence($line) { |
|
1051 | 1051 | $array = array(); |
1052 | - $key = self::unquote(trim(substr($line,1,-1))); |
|
1052 | + $key = self::unquote(trim(substr($line, 1, -1))); |
|
1053 | 1053 | $array[$key] = array(); |
1054 | - $this->delayedPath = array(strpos ($line, $key) + $this->indent => $key); |
|
1054 | + $this->delayedPath = array(strpos($line, $key) + $this->indent => $key); |
|
1055 | 1055 | return array($array); |
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | private function checkKeysInValue($value) { |
1059 | 1059 | if (strchr('[{"\'', $value[0]) === false) { |
1060 | 1060 | if (strchr($value, ': ') !== false) { |
1061 | - throw new Exception('Too many keys: '.$value); |
|
1061 | + throw new Exception('Too many keys: ' . $value); |
|
1062 | 1062 | } |
1063 | 1063 | } |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - private function returnMappedValue ($line) { |
|
1066 | + private function returnMappedValue($line) { |
|
1067 | 1067 | $this->checkKeysInValue($line); |
1068 | 1068 | $array = array(); |
1069 | - $key = self::unquote (trim(substr($line,0,-1))); |
|
1069 | + $key = self::unquote(trim(substr($line, 0, -1))); |
|
1070 | 1070 | $array[$key] = ''; |
1071 | 1071 | return $array; |
1072 | 1072 | } |
1073 | 1073 | |
1074 | - private function startsMappedValue ($line) { |
|
1075 | - return (substr ($line, -1, 1) == ':'); |
|
1074 | + private function startsMappedValue($line) { |
|
1075 | + return (substr($line, -1, 1) == ':'); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | - private function isPlainArray ($line) { |
|
1079 | - return ($line[0] == '[' && substr ($line, -1, 1) == ']'); |
|
1078 | + private function isPlainArray($line) { |
|
1079 | + return ($line[0] == '[' && substr($line, -1, 1) == ']'); |
|
1080 | 1080 | } |
1081 | 1081 | |
1082 | - private function returnPlainArray ($line) { |
|
1082 | + private function returnPlainArray($line) { |
|
1083 | 1083 | return $this->_toType($line); |
1084 | 1084 | } |
1085 | 1085 | |
1086 | - private function returnKeyValuePair ($line) { |
|
1086 | + private function returnKeyValuePair($line) { |
|
1087 | 1087 | $array = array(); |
1088 | 1088 | $key = ''; |
1089 | - if (strpos ($line, ': ')) { |
|
1089 | + if (strpos($line, ': ')) { |
|
1090 | 1090 | // It's a key/value pair most likely |
1091 | 1091 | // If the key is in double quotes pull it out |
1092 | - if (($line[0] == '"' || $line[0] == "'") && preg_match('/^(["\'](.*)["\'](\s)*:)/',$line,$matches)) { |
|
1093 | - $value = trim(str_replace($matches[1],'',$line)); |
|
1092 | + if (($line[0] == '"' || $line[0] == "'") && preg_match('/^(["\'](.*)["\'](\s)*:)/', $line, $matches)) { |
|
1093 | + $value = trim(str_replace($matches[1], '', $line)); |
|
1094 | 1094 | $key = $matches[2]; |
1095 | 1095 | } else { |
1096 | 1096 | // Do some guesswork as to the key and the value |
@@ -1104,17 +1104,17 @@ discard block |
||
1104 | 1104 | if ($key === '0') $key = '__!YAMLZero'; |
1105 | 1105 | $array[$key] = $value; |
1106 | 1106 | } else { |
1107 | - $array = array ($line); |
|
1107 | + $array = array($line); |
|
1108 | 1108 | } |
1109 | 1109 | return $array; |
1110 | 1110 | |
1111 | 1111 | } |
1112 | 1112 | |
1113 | 1113 | |
1114 | - private function returnArrayElement ($line) { |
|
1114 | + private function returnArrayElement($line) { |
|
1115 | 1115 | if (strlen($line) <= 1) return array(array()); // Weird %) |
1116 | 1116 | $array = array(); |
1117 | - $value = trim(substr($line,1)); |
|
1117 | + $value = trim(substr($line, 1)); |
|
1118 | 1118 | $value = $this->_toType($value); |
1119 | 1119 | if ($this->isArrayElement($value)) { |
1120 | 1120 | $value = $this->returnArrayElement($value); |
@@ -1124,25 +1124,25 @@ discard block |
||
1124 | 1124 | } |
1125 | 1125 | |
1126 | 1126 | |
1127 | - private function nodeContainsGroup ($line) { |
|
1127 | + private function nodeContainsGroup($line) { |
|
1128 | 1128 | $symbolsForReference = 'A-z0-9_\-'; |
1129 | 1129 | if (strpos($line, '&') === false && strpos($line, '*') === false) return false; // Please die fast ;-) |
1130 | - if ($line[0] == '&' && preg_match('/^(&['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1]; |
|
1131 | - if ($line[0] == '*' && preg_match('/^(\*['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1]; |
|
1132 | - if (preg_match('/(&['.$symbolsForReference.']+)$/', $line, $matches)) return $matches[1]; |
|
1133 | - if (preg_match('/(\*['.$symbolsForReference.']+$)/', $line, $matches)) return $matches[1]; |
|
1134 | - if (preg_match ('#^\s*<<\s*:\s*(\*[^\s]+).*$#', $line, $matches)) return $matches[1]; |
|
1130 | + if ($line[0] == '&' && preg_match('/^(&[' . $symbolsForReference . ']+)/', $line, $matches)) return $matches[1]; |
|
1131 | + if ($line[0] == '*' && preg_match('/^(\*[' . $symbolsForReference . ']+)/', $line, $matches)) return $matches[1]; |
|
1132 | + if (preg_match('/(&[' . $symbolsForReference . ']+)$/', $line, $matches)) return $matches[1]; |
|
1133 | + if (preg_match('/(\*[' . $symbolsForReference . ']+$)/', $line, $matches)) return $matches[1]; |
|
1134 | + if (preg_match('#^\s*<<\s*:\s*(\*[^\s]+).*$#', $line, $matches)) return $matches[1]; |
|
1135 | 1135 | return false; |
1136 | 1136 | |
1137 | 1137 | } |
1138 | 1138 | |
1139 | - private function addGroup ($line, $group) { |
|
1140 | - if ($group[0] == '&') $this->_containsGroupAnchor = substr ($group, 1); |
|
1141 | - if ($group[0] == '*') $this->_containsGroupAlias = substr ($group, 1); |
|
1139 | + private function addGroup($line, $group) { |
|
1140 | + if ($group[0] == '&') $this->_containsGroupAnchor = substr($group, 1); |
|
1141 | + if ($group[0] == '*') $this->_containsGroupAlias = substr($group, 1); |
|
1142 | 1142 | //print_r ($this->path); |
1143 | 1143 | } |
1144 | 1144 | |
1145 | - private function stripGroup ($line, $group) { |
|
1145 | + private function stripGroup($line, $group) { |
|
1146 | 1146 | $line = trim(str_replace($group, '', $line)); |
1147 | 1147 | return $line; |
1148 | 1148 | } |
@@ -1155,7 +1155,7 @@ discard block |
||
1155 | 1155 | do { |
1156 | 1156 | if (PHP_SAPI != 'cli') break; |
1157 | 1157 | if (empty ($_SERVER['argc']) || $_SERVER['argc'] < 2) break; |
1158 | - if (empty ($_SERVER['PHP_SELF']) || FALSE === strpos ($_SERVER['PHP_SELF'], 'Spyc.php') ) break; |
|
1158 | + if (empty ($_SERVER['PHP_SELF']) || FALSE === strpos($_SERVER['PHP_SELF'], 'Spyc.php')) break; |
|
1159 | 1159 | $file = $argv[1]; |
1160 | - echo json_encode (spyc_load_file ($file)); |
|
1160 | + echo json_encode(spyc_load_file($file)); |
|
1161 | 1161 | } while (0); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param Writing_On_GitHub $app Application container. |
36 | 36 | */ |
37 | - public function __construct( Writing_On_GitHub $app ) { |
|
37 | + public function __construct(Writing_On_GitHub $app) { |
|
38 | 38 | $this->app = $app; |
39 | 39 | } |
40 | 40 | |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | $this->raw_data = $this->read_raw_data(); |
50 | 50 | |
51 | 51 | // Validate request secret. |
52 | - $hash = hash_hmac( 'sha1', $this->raw_data, $this->secret() ); |
|
53 | - if ( 'sha1=' . $hash !== $headers['X-Hub-Signature'] ) { |
|
52 | + $hash = hash_hmac('sha1', $this->raw_data, $this->secret()); |
|
53 | + if ('sha1=' . $hash !== $headers['X-Hub-Signature']) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @return Writing_On_GitHub_Payload |
91 | 91 | */ |
92 | 92 | public function payload() { |
93 | - return new Writing_On_GitHub_Payload( $this->app, $this->raw_data ); |
|
93 | + return new Writing_On_GitHub_Payload($this->app, $this->raw_data); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | * @return array |
102 | 102 | */ |
103 | 103 | protected function headers() { |
104 | - if ( $this->headers ) { |
|
104 | + if ($this->headers) { |
|
105 | 105 | return $this->headers; |
106 | 106 | } |
107 | 107 | |
108 | - if ( function_exists( 'getallheaders' ) ) { |
|
108 | + if (function_exists('getallheaders')) { |
|
109 | 109 | |
110 | 110 | $this->headers = getallheaders(); |
111 | 111 | return $this->headers; |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | * @see http://www.php.net/manual/en/function.getallheaders.php |
116 | 116 | */ |
117 | 117 | $this->headers = array(); |
118 | - foreach ( $_SERVER as $name => $value ) { |
|
119 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
120 | - $this->headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
118 | + foreach ($_SERVER as $name => $value) { |
|
119 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
120 | + $this->headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @return string |
131 | 131 | */ |
132 | 132 | protected function read_raw_data() { |
133 | - return file_get_contents( 'php://input' ); |
|
133 | + return file_get_contents('php://input'); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,6 +139,6 @@ discard block |
||
139 | 139 | * @return string |
140 | 140 | */ |
141 | 141 | protected function secret() { |
142 | - return get_option( 'wogh_secret' ); |
|
142 | + return get_option('wogh_secret'); |
|
143 | 143 | } |
144 | 144 | } |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __construct() { |
38 | 38 | // Clear out previously saved information. |
39 | - if ( get_option( '_wogh_api_cache' ) ) { |
|
40 | - delete_option( '_wogh_api_cache' ); |
|
39 | + if (get_option('_wogh_api_cache')) { |
|
40 | + delete_option('_wogh_api_cache'); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return false|Writing_On_GitHub_Blob |
50 | 50 | */ |
51 | - public function fetch_blob( $sha ) { |
|
52 | - $blob = $this->get( 'blobs', $sha ); |
|
51 | + public function fetch_blob($sha) { |
|
52 | + $blob = $this->get('blobs', $sha); |
|
53 | 53 | |
54 | - if ( $blob instanceof Writing_On_GitHub_Blob ) { |
|
54 | + if ($blob instanceof Writing_On_GitHub_Blob) { |
|
55 | 55 | return $blob; |
56 | 56 | } |
57 | 57 | |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return Writing_On_GitHub_Blob |
68 | 68 | */ |
69 | - public function set_blob( $sha, Writing_On_GitHub_Blob $blob ) { |
|
70 | - return $this->save( 'blobs', $sha, $blob, 3 * DAY_IN_SECONDS ); |
|
69 | + public function set_blob($sha, Writing_On_GitHub_Blob $blob) { |
|
70 | + return $this->save('blobs', $sha, $blob, 3 * DAY_IN_SECONDS); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return stdClass|false response object if cached, false if not |
80 | 80 | */ |
81 | - protected function get( $type, $sha ) { |
|
82 | - if ( isset( $this->{$type}[ $sha ] ) ) { |
|
83 | - return $this->{$type}[ $sha ]; |
|
81 | + protected function get($type, $sha) { |
|
82 | + if (isset($this->{$type}[$sha])) { |
|
83 | + return $this->{$type}[$sha]; |
|
84 | 84 | } |
85 | 85 | |
86 | - if ( $data = get_transient( $this->cache_id( $type, $sha ) ) ) { |
|
87 | - return $this->{$type}[ $sha ] = $data; |
|
86 | + if ($data = get_transient($this->cache_id($type, $sha))) { |
|
87 | + return $this->{$type}[$sha] = $data; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | return false; |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return mixed |
102 | 102 | */ |
103 | - protected function save( $type, $sha, $data, $time ) { |
|
104 | - $this->{$type}[ $sha ] = $data; |
|
103 | + protected function save($type, $sha, $data, $time) { |
|
104 | + $this->{$type}[$sha] = $data; |
|
105 | 105 | |
106 | - set_transient( $this->cache_id( $type, $sha ), $data, $time ); |
|
106 | + set_transient($this->cache_id($type, $sha), $data, $time); |
|
107 | 107 | |
108 | 108 | return $data; |
109 | 109 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return string |
118 | 118 | */ |
119 | - protected function cache_id( $type, $sha ) { |
|
120 | - return 'wogh_' . md5( $type . '_' . $sha ); |
|
119 | + protected function cache_id($type, $sha) { |
|
120 | + return 'wogh_' . md5($type . '_' . $sha); |
|
121 | 121 | } |
122 | 122 | } |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | */ |
17 | 17 | protected function export_user() { |
18 | 18 | $user_id = get_current_user_id(); |
19 | - $user = get_userdata( $user_id ); |
|
19 | + $user = get_userdata($user_id); |
|
20 | 20 | |
21 | - if ( $user ) { |
|
21 | + if ($user) { |
|
22 | 22 | return array( |
23 | 23 | 'name' => $user->display_name, |
24 | 24 | 'email' => $user->user_email, |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return array |
35 | 35 | */ |
36 | - public function delete_file( $path, $sha, $message ) { |
|
36 | + public function delete_file($path, $sha, $message) { |
|
37 | 37 | $body = new stdClass(); |
38 | 38 | $body->message = $message; |
39 | 39 | $body->sha = $sha; |
40 | 40 | $body->branch = $this->branch(); |
41 | 41 | |
42 | - if ( $author = $this->export_user() ) { |
|
42 | + if ($author = $this->export_user()) { |
|
43 | 43 | $body->author = $author; |
44 | 44 | } |
45 | 45 | |
46 | - return $this->call( 'DELETE', $this->content_endpoint( $path ), $body ); |
|
46 | + return $this->call('DELETE', $this->content_endpoint($path), $body); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,17 +51,17 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - public function create_file( $blob, $message ) { |
|
54 | + public function create_file($blob, $message) { |
|
55 | 55 | $body = $blob->to_body(); |
56 | 56 | $body->message = $message; |
57 | 57 | $body->branch = $this->branch(); |
58 | 58 | unset($body->sha); |
59 | 59 | |
60 | - if ( $author = $this->export_user() ) { |
|
60 | + if ($author = $this->export_user()) { |
|
61 | 61 | $body->author = $author; |
62 | 62 | } |
63 | 63 | |
64 | - return $this->call( 'PUT', $this->content_endpoint( $blob->path() ), $body ); |
|
64 | + return $this->call('PUT', $this->content_endpoint($blob->path()), $body); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -69,15 +69,15 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return array |
71 | 71 | */ |
72 | - public function update_file( $blob, $message ) { |
|
72 | + public function update_file($blob, $message) { |
|
73 | 73 | $body = $blob->to_body(); |
74 | 74 | $body->message = $message; |
75 | 75 | $body->branch = $this->branch(); |
76 | 76 | |
77 | - if ( $author = $this->export_user() ) { |
|
77 | + if ($author = $this->export_user()) { |
|
78 | 78 | $body->author = $author; |
79 | 79 | } |
80 | 80 | |
81 | - return $this->call( 'PUT', $this->content_endpoint( $blob->path() ), $body ); |
|
81 | + return $this->call('PUT', $this->content_endpoint($blob->path()), $body); |
|
82 | 82 | } |
83 | 83 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param Writing_On_GitHub $app Application container. |
28 | 28 | */ |
29 | - public function __construct( Writing_On_GitHub $app ) { |
|
29 | + public function __construct(Writing_On_GitHub $app) { |
|
30 | 30 | $this->app = $app; |
31 | 31 | } |
32 | 32 | |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @return stdClass|WP_Error |
41 | 41 | */ |
42 | - protected function call( $method, $endpoint, $body = array() ) { |
|
43 | - if ( is_wp_error( $error = $this->can_call() ) ) { |
|
42 | + protected function call($method, $endpoint, $body = array()) { |
|
43 | + if (is_wp_error($error = $this->can_call())) { |
|
44 | 44 | return $error; |
45 | 45 | } |
46 | 46 | |
@@ -51,24 +51,23 @@ discard block |
||
51 | 51 | ), |
52 | 52 | ); |
53 | 53 | |
54 | - if ( 'GET' !== $method ) { |
|
55 | - $args['body'] = function_exists( 'wp_json_encode' ) ? |
|
56 | - wp_json_encode( $body ) : |
|
57 | - json_encode( $body ); |
|
54 | + if ('GET' !== $method) { |
|
55 | + $args['body'] = function_exists('wp_json_encode') ? |
|
56 | + wp_json_encode($body) : json_encode($body); |
|
58 | 57 | } |
59 | 58 | |
60 | 59 | $tmpbody = isset($args['body']) ? $args['body'] : ''; |
61 | 60 | error_log("writing-on-github-call $method $endpoint $tmpbody"); |
62 | 61 | |
63 | - $response = wp_remote_request( $endpoint, $args ); |
|
64 | - $status = wp_remote_retrieve_header( $response, 'status' ); |
|
65 | - $body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
62 | + $response = wp_remote_request($endpoint, $args); |
|
63 | + $status = wp_remote_retrieve_header($response, 'status'); |
|
64 | + $body = json_decode(wp_remote_retrieve_body($response)); |
|
66 | 65 | |
67 | - if ( '2' !== substr( $status, 0, 1 ) && '3' !== substr( $status, 0, 1 ) ) { |
|
66 | + if ('2' !== substr($status, 0, 1) && '3' !== substr($status, 0, 1)) { |
|
68 | 67 | return new WP_Error( |
69 | - strtolower( str_replace( ' ', '_', $status ) ), |
|
68 | + strtolower(str_replace(' ', '_', $status)), |
|
70 | 69 | sprintf( |
71 | - __( 'Method %s to endpoint %s failed with error: %s', 'writing-on-github' ), |
|
70 | + __('Method %s to endpoint %s failed with error: %s', 'writing-on-github'), |
|
72 | 71 | $method, |
73 | 72 | $endpoint, |
74 | 73 | $body && $body->message ? $body->message : 'Unknown error' |
@@ -85,28 +84,28 @@ discard block |
||
85 | 84 | * @return true|WP_Error |
86 | 85 | */ |
87 | 86 | protected function can_call() { |
88 | - if ( ! $this->oauth_token() ) { |
|
87 | + if ( ! $this->oauth_token()) { |
|
89 | 88 | return new WP_Error( |
90 | 89 | 'missing_token', |
91 | - __( 'Writing On GitHub needs an auth token. Please update your settings.', 'writing-on-github' ) |
|
90 | + __('Writing On GitHub needs an auth token. Please update your settings.', 'writing-on-github') |
|
92 | 91 | ); |
93 | 92 | } |
94 | 93 | |
95 | 94 | $repo = $this->repository(); |
96 | 95 | |
97 | - if ( ! $repo ) { |
|
96 | + if ( ! $repo) { |
|
98 | 97 | return new WP_Error( |
99 | 98 | 'missing_repository', |
100 | - __( 'Writing On GitHub needs a repository. Please update your settings.', 'writing-on-github' ) |
|
99 | + __('Writing On GitHub needs a repository. Please update your settings.', 'writing-on-github') |
|
101 | 100 | ); |
102 | 101 | } |
103 | 102 | |
104 | - $parts = explode( '/', $repo ); |
|
103 | + $parts = explode('/', $repo); |
|
105 | 104 | |
106 | - if ( 2 !== count( $parts ) ) { |
|
105 | + if (2 !== count($parts)) { |
|
107 | 106 | return new WP_Error( |
108 | 107 | 'malformed_repository', |
109 | - __( 'Writing On GitHub needs a properly formed repository. Please update your settings.', 'writing-on-github' ) |
|
108 | + __('Writing On GitHub needs a properly formed repository. Please update your settings.', 'writing-on-github') |
|
110 | 109 | ); |
111 | 110 | } |
112 | 111 | |
@@ -119,7 +118,7 @@ discard block |
||
119 | 118 | * @return string |
120 | 119 | */ |
121 | 120 | public function repository() { |
122 | - return (string) get_option( self::REPO_OPTION_KEY ); |
|
121 | + return (string) get_option(self::REPO_OPTION_KEY); |
|
123 | 122 | } |
124 | 123 | |
125 | 124 | /** |
@@ -128,18 +127,18 @@ discard block |
||
128 | 127 | * @return string |
129 | 128 | */ |
130 | 129 | public function oauth_token() { |
131 | - return (string) get_option( self::TOKEN_OPTION_KEY ); |
|
130 | + return (string) get_option(self::TOKEN_OPTION_KEY); |
|
132 | 131 | } |
133 | 132 | |
134 | 133 | /** |
135 | 134 | * Returns the GitHub host to sync with (for GitHub Enterprise support) |
136 | 135 | */ |
137 | 136 | public function api_base() { |
138 | - return get_option( self::HOST_OPTION_KEY ); |
|
137 | + return get_option(self::HOST_OPTION_KEY); |
|
139 | 138 | } |
140 | 139 | |
141 | 140 | public function branch() { |
142 | - $branch = get_option( self::BRANCH_OPTION_KEY ); |
|
141 | + $branch = get_option(self::BRANCH_OPTION_KEY); |
|
143 | 142 | return $branch ? $branch : 'master'; |
144 | 143 | } |
145 | 144 | |
@@ -200,11 +199,11 @@ discard block |
||
200 | 199 | * |
201 | 200 | * Returns String the relative API call path |
202 | 201 | */ |
203 | - public function content_endpoint( $path = false ) { |
|
202 | + public function content_endpoint($path = false) { |
|
204 | 203 | $url = $this->api_base() . '/repos/'; |
205 | 204 | $url = $url . $this->repository() . '/contents'; |
206 | 205 | |
207 | - if ( ! empty($path) ) { |
|
206 | + if ( ! empty($path)) { |
|
208 | 207 | $url .= '/' . $path; |
209 | 208 | } |
210 | 209 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param Writing_On_GitHub $app Application container. |
23 | 23 | */ |
24 | - public function __construct( Writing_On_GitHub $app ) { |
|
24 | + public function __construct(Writing_On_GitHub $app) { |
|
25 | 25 | $this->app = $app; |
26 | 26 | } |
27 | 27 | |
@@ -32,30 +32,30 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return false |
34 | 34 | */ |
35 | - public function error( WP_Error $error ) { |
|
35 | + public function error(WP_Error $error) { |
|
36 | 36 | global $wp_version; |
37 | 37 | |
38 | - $this->log( $error ); |
|
38 | + $this->log($error); |
|
39 | 39 | |
40 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX && defined( 'WOGH_AJAX' ) && WOGH_AJAX ) { |
|
40 | + if (defined('DOING_AJAX') && DOING_AJAX && defined('WOGH_AJAX') && WOGH_AJAX) { |
|
41 | 41 | /** |
42 | 42 | * WordPress 4.1.0 introduced allowing WP_Error objects to be |
43 | 43 | * passed directly into `wp_send_json_error`. This shims in |
44 | 44 | * compatibility for older versions. We're currently supporting 3.9+. |
45 | 45 | */ |
46 | - if ( version_compare( $wp_version, '4.1.0', '<' ) ) { |
|
46 | + if (version_compare($wp_version, '4.1.0', '<')) { |
|
47 | 47 | $result = array(); |
48 | 48 | |
49 | - foreach ( $error->errors as $code => $messages ) { |
|
50 | - foreach ( $messages as $message ) { |
|
51 | - $result[] = array( 'code' => $code, 'message' => $message ); |
|
49 | + foreach ($error->errors as $code => $messages) { |
|
50 | + foreach ($messages as $message) { |
|
51 | + $result[] = array('code' => $code, 'message' => $message); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | 55 | $error = $result; |
56 | 56 | } |
57 | 57 | |
58 | - wp_send_json_error( $error ); |
|
58 | + wp_send_json_error($error); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | return false; |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @return true |
70 | 70 | */ |
71 | - public function success( $success ) { |
|
72 | - $this->log( $success ); |
|
71 | + public function success($success) { |
|
72 | + $this->log($success); |
|
73 | 73 | |
74 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX && defined( 'WOGH_AJAX' ) && WOGH_AJAX ) { |
|
75 | - wp_send_json_success( $success ); |
|
74 | + if (defined('DOING_AJAX') && DOING_AJAX && defined('WOGH_AJAX') && WOGH_AJAX) { |
|
75 | + wp_send_json_success($success); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return true; |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param string|WP_Error $msg Message to log. |
87 | 87 | */ |
88 | - protected function log( $msg ) { |
|
89 | - if ( is_wp_error( $msg ) ) { |
|
88 | + protected function log($msg) { |
|
89 | + if (is_wp_error($msg)) { |
|
90 | 90 | $msg = $msg->get_error_message(); |
91 | 91 | } |
92 | 92 | |
93 | - Writing_On_GitHub::write_log( $msg ); |
|
93 | + Writing_On_GitHub::write_log($msg); |
|
94 | 94 | } |
95 | 95 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * @param Writing_On_GitHub $app Application container. |
30 | 30 | * @param string $raw_data Raw request data. |
31 | 31 | */ |
32 | - public function __construct( Writing_On_GitHub $app, $raw_data ) { |
|
32 | + public function __construct(Writing_On_GitHub $app, $raw_data) { |
|
33 | 33 | $this->app = $app; |
34 | - $this->data = json_decode( $raw_data ); |
|
34 | + $this->data = json_decode($raw_data); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -41,32 +41,32 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function should_import() { |
43 | 43 | // @todo how do we get this without importing the whole api object just for this? |
44 | - if ( strtolower( $this->data->repository->full_name ) !== strtolower( $this->app->api()->fetch()->repository() ) ) { |
|
44 | + if (strtolower($this->data->repository->full_name) !== strtolower($this->app->api()->fetch()->repository())) { |
|
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // The last term in the ref is the payload_branch name. |
49 | - $refs = explode( '/', $this->data->ref ); |
|
50 | - $payload_branch = array_pop( $refs ); |
|
49 | + $refs = explode('/', $this->data->ref); |
|
50 | + $payload_branch = array_pop($refs); |
|
51 | 51 | |
52 | 52 | $branch = $this->app->api()->fetch()->branch(); |
53 | 53 | |
54 | - if ( $branch !== $payload_branch ) { |
|
54 | + if ($branch !== $payload_branch) { |
|
55 | 55 | return false; |
56 | 56 | } |
57 | 57 | |
58 | 58 | // We add a tag to commits we push out, so we shouldn't pull them in again. |
59 | - $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' ); |
|
59 | + $tag = apply_filters('wogh_commit_msg_tag', 'wogh'); |
|
60 | 60 | |
61 | - if ( ! $tag ) { |
|
62 | - throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) ); |
|
61 | + if ( ! $tag) { |
|
62 | + throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github')); |
|
63 | 63 | } |
64 | 64 | |
65 | - if ( $tag === substr( $this->message(), -1 * strlen( $tag ) ) ) { |
|
65 | + if ($tag === substr($this->message(), -1 * strlen($tag))) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - if ( ! $this->get_commit_id() ) { |
|
69 | + if ( ! $this->get_commit_id()) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param Writing_On_GitHub $app Application container. |
37 | 37 | */ |
38 | - public function __construct( Writing_On_GitHub $app ) { |
|
38 | + public function __construct(Writing_On_GitHub $app) { |
|
39 | 39 | $this->app = $app; |
40 | 40 | } |
41 | 41 | |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @return Writing_On_GitHub_Fetch_Client |
46 | 46 | */ |
47 | 47 | public function fetch() { |
48 | - if ( ! $this->fetch ) { |
|
49 | - $this->fetch = new Writing_On_GitHub_Fetch_Client( $this->app ); |
|
48 | + if ( ! $this->fetch) { |
|
49 | + $this->fetch = new Writing_On_GitHub_Fetch_Client($this->app); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | return $this->fetch; |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | * @return Writing_On_GitHub_Persist_Client |
59 | 59 | */ |
60 | 60 | public function persist() { |
61 | - if ( ! $this->persist ) { |
|
62 | - $this->persist = new Writing_On_GitHub_Persist_Client( $this->app ); |
|
61 | + if ( ! $this->persist) { |
|
62 | + $this->persist = new Writing_On_GitHub_Persist_Client($this->app); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | return $this->persist; |
@@ -6,13 +6,13 @@ |
||
6 | 6 | */ |
7 | 7 | class Writing_On_GitHub_File_Info { |
8 | 8 | |
9 | - public function __construct( stdClass $data ) { |
|
9 | + public function __construct(stdClass $data) { |
|
10 | 10 | $this->sha = $data->sha; |
11 | 11 | $this->path = $data->path; |
12 | - $this->status = $data->status; |
|
12 | + $this->status = $data->status; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | public $sha; |
16 | 16 | public $path; |
17 | - public $status; // added removed modified |
|
17 | + public $status; // added removed modified |
|
18 | 18 | } |