| Conditions | 1 |
| Paths | 1 |
| Total Lines | 78 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 30 | public function testValidValueValidate(): void |
||
| 31 | { |
||
| 32 | // JSON test from http://www.json.org/JSON_checker/test/pass1.json |
||
| 33 | $json1 = <<<'JSON' |
||
| 34 | [ |
||
| 35 | "JSON Test Pattern pass1", |
||
| 36 | {"object with 1 member":["array with 1 element"]}, |
||
| 37 | {}, |
||
| 38 | [], |
||
| 39 | -42, |
||
| 40 | true, |
||
| 41 | false, |
||
| 42 | null, |
||
| 43 | { |
||
| 44 | "integer": 1234567890, |
||
| 45 | "real": -9876.543210, |
||
| 46 | "e": 0.123456789e-12, |
||
| 47 | "E": 1.234567890E+34, |
||
| 48 | "": 23456789012E66, |
||
| 49 | "zero": 0, |
||
| 50 | "one": 1, |
||
| 51 | "space": " ", |
||
| 52 | "quote": "\"", |
||
| 53 | "backslash": "\\", |
||
| 54 | "controls": "\b\f\n\r\t", |
||
| 55 | "slash": "/ & \/", |
||
| 56 | "alpha": "abcdefghijklmnopqrstuvwyz", |
||
| 57 | "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", |
||
| 58 | "digit": "0123456789", |
||
| 59 | "0123456789": "digit", |
||
| 60 | "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?", |
||
| 61 | "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", |
||
| 62 | "true": true, |
||
| 63 | "false": false, |
||
| 64 | "null": null, |
||
| 65 | "array":[ ], |
||
| 66 | "object":{ }, |
||
| 67 | "address": "50 St. James Street", |
||
| 68 | "url": "http://www.JSON.org/", |
||
| 69 | "comment": "// /* <!-- --", |
||
| 70 | "# -- --> */": " ", |
||
| 71 | " s p a c e d " :[1,2 , 3 |
||
| 72 | |||
| 73 | , |
||
| 74 | |||
| 75 | 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], |
||
| 76 | "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", |
||
| 77 | "quotes": "" \u0022 %22 0x22 034 "", |
||
| 78 | "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" |
||
| 79 | : "A key can be any string" |
||
| 80 | }, |
||
| 81 | 0.5 ,98.6 |
||
| 82 | , |
||
| 83 | 99.44 |
||
| 84 | , |
||
| 85 | |||
| 86 | 1066, |
||
| 87 | 1e1, |
||
| 88 | 0.1e1, |
||
| 89 | 1e-1, |
||
| 90 | 1e00,2e+00,2e-00 |
||
| 91 | ,"rosebud"] |
||
| 92 | JSON; |
||
| 93 | // JSON test from http://www.json.org/JSON_checker/test/pass2.json |
||
| 94 | $json2 = '[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]'; |
||
| 95 | // JSON test from http://www.json.org/JSON_checker/test/pass3.json |
||
| 96 | $json3 = <<<'JSON' |
||
| 97 | { |
||
| 98 | "JSON Test Pattern pass3": { |
||
| 99 | "The outermost value": "must be an object or array.", |
||
| 100 | "In this test": "It is an object." |
||
| 101 | } |
||
| 102 | } |
||
| 103 | JSON; |
||
| 104 | |||
| 105 | $this->assertTrue((new Json())->validate($json1)->isValid()); |
||
| 106 | $this->assertTrue((new Json())->validate($json2)->isValid()); |
||
| 107 | $this->assertTrue((new Json())->validate($json3)->isValid()); |
||
| 108 | } |
||
| 130 |