diff --git a/.gitignore b/.gitignore index 75b2efc..87f5e50 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ vendor +coverage.xml diff --git a/bin/cache.php b/bin/cache.php new file mode 100644 index 0000000..de3cb4f --- /dev/null +++ b/bin/cache.php @@ -0,0 +1,21 @@ +=5.4.16", + "squizlabs/php_codesniffer": "~2.3" + }, + "bin": [ + "bin/tokenize", + "bin/sniff" + ], + "type": "library", + "autoload": { + "psr-4": { + "PSR2R\\": "PSR2R" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Scherer", + "homepage": "http://www.dereuromark.de", + "role": "Contributor" + } + ], + "description": "Code-Sniffer, Auto-Fixer and Tokenizer for PSR2-R", + "time": "2016-07-11T14:35:34+00:00" + }, + { + "name": "humanmade/coding-standards", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/humanmade/coding-standards.git", + "reference": "1f1d90c937b1057f1c0999ac65f501db7c72f46c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/humanmade/coding-standards/zipball/1f1d90c937b1057f1c0999ac65f501db7c72f46c", + "reference": "1f1d90c937b1057f1c0999ac65f501db7c72f46c", + "shasum": "" + }, + "require": { + "fig-r/psr2r-sniffer": "^0.3.1", + "wp-coding-standards/wpcs": "^0.10.0" + }, + "type": "project", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0" + ], + "description": "Human Made coding standards", + "time": "2016-12-08T08:41:35+00:00" + }, { "name": "myclabs/deep-copy", - "version": "1.5.4", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "ea74994a3dc7f8d2f65a06009348f2d63c81e61f" + "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/ea74994a3dc7f8d2f65a06009348f2d63c81e61f", - "reference": "ea74994a3dc7f8d2f65a06009348f2d63c81e61f", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/8e6e04167378abf1ddb4d3522d8755c5fd90d102", + "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102", "shasum": "" }, "require": { @@ -209,7 +284,7 @@ "object", "object graph" ], - "time": "2016-09-16T13:37:59+00:00" + "time": "2017-04-12T18:52:22+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -312,16 +387,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "0.2", + "version": "0.2.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443" + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b39c7a5b194f9ed7bd0dd345c751007a41862443", - "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", "shasum": "" }, "require": { @@ -355,31 +430,32 @@ "email": "me@mikevanriel.com" } ], - "time": "2016-06-10T07:14:17+00:00" + "time": "2016-11-25T06:54:22+00:00" }, { "name": "phpspec/prophecy", - "version": "v1.6.1", + "version": "v1.7.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "58a8137754bc24b25740d4281399a4a3596058e0" + "reference": "93d39f1f7f9326d746203c7c056f300f7f126073" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/58a8137754bc24b25740d4281399a4a3596058e0", - "reference": "58a8137754bc24b25740d4281399a4a3596058e0", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/93d39f1f7f9326d746203c7c056f300f7f126073", + "reference": "93d39f1f7f9326d746203c7c056f300f7f126073", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", - "sebastian/comparator": "^1.1", - "sebastian/recursion-context": "^1.0" + "sebastian/comparator": "^1.1|^2.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, "require-dev": { - "phpspec/phpspec": "^2.0" + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8 || ^5.6.5" }, "type": "library", "extra": { @@ -417,39 +493,39 @@ "spy", "stub" ], - "time": "2016-06-07T08:13:47+00:00" + "time": "2017-03-02T20:05:34+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "4.0.1", + "version": "4.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "5f3f7e736d6319d5f1fc402aff8b026da26709a3" + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/5f3f7e736d6319d5f1fc402aff8b026da26709a3", - "reference": "5f3f7e736d6319d5f1fc402aff8b026da26709a3", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", "shasum": "" }, "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", "php": "^5.6 || ^7.0", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "^1.4.2", - "sebastian/code-unit-reverse-lookup": "~1.0", + "phpunit/php-file-iterator": "^1.3", + "phpunit/php-text-template": "^1.2", + "phpunit/php-token-stream": "^1.4.2 || ^2.0", + "sebastian/code-unit-reverse-lookup": "^1.0", "sebastian/environment": "^1.3.2 || ^2.0", - "sebastian/version": "~1.0|~2.0" + "sebastian/version": "^1.0 || ^2.0" }, "require-dev": { - "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "^5.4" + "ext-xdebug": "^2.1.4", + "phpunit/phpunit": "^5.7" }, "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.4.0", - "ext-xmlwriter": "*" + "ext-xdebug": "^2.5.1" }, "type": "library", "extra": { @@ -480,20 +556,20 @@ "testing", "xunit" ], - "time": "2016-07-26T14:39:29+00:00" + "time": "2017-04-02T07:44:40+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.1", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", "shasum": "" }, "require": { @@ -527,7 +603,7 @@ "filesystem", "iterator" ], - "time": "2015-06-21T13:08:43+00:00" + "time": "2016-10-03T07:40:28+00:00" }, { "name": "phpunit/php-text-template", @@ -572,25 +648,30 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.8", + "version": "1.0.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", - "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4|~5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -612,20 +693,20 @@ "keywords": [ "timer" ], - "time": "2016-05-12T18:03:57+00:00" + "time": "2017-02-26T11:10:40+00:00" }, { "name": "phpunit/php-token-stream", - "version": "1.4.8", + "version": "1.4.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da" + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", - "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", "shasum": "" }, "require": { @@ -661,50 +742,54 @@ "keywords": [ "tokenizer" ], - "time": "2015-09-15T10:49:45+00:00" + "time": "2017-02-27T10:12:30+00:00" }, { "name": "phpunit/phpunit", - "version": "5.5.0", + "version": "5.7.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c7b3e1dcc1d183f26d5ba282881fe65c2cbb5b2b" + "reference": "3cb94a5f8c07a03c8b7527ed7468a2926203f58b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c7b3e1dcc1d183f26d5ba282881fe65c2cbb5b2b", - "reference": "c7b3e1dcc1d183f26d5ba282881fe65c2cbb5b2b", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3cb94a5f8c07a03c8b7527ed7468a2926203f58b", + "reference": "3cb94a5f8c07a03c8b7527ed7468a2926203f58b", "shasum": "" }, "require": { "ext-dom": "*", "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", "myclabs/deep-copy": "~1.3", "php": "^5.6 || ^7.0", - "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "^4.0.1", + "phpspec/prophecy": "^1.6.2", + "phpunit/php-code-coverage": "^4.0.4", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", "phpunit/php-timer": "^1.0.6", "phpunit/phpunit-mock-objects": "^3.2", - "sebastian/comparator": "~1.1", - "sebastian/diff": "~1.2", - "sebastian/environment": "^1.3 || ^2.0", - "sebastian/exporter": "~1.2", - "sebastian/global-state": "~1.0", - "sebastian/object-enumerator": "~1.0", + "sebastian/comparator": "^1.2.4", + "sebastian/diff": "^1.4.3", + "sebastian/environment": "^1.3.4 || ^2.0", + "sebastian/exporter": "~2.0", + "sebastian/global-state": "^1.1", + "sebastian/object-enumerator": "~2.0", "sebastian/resource-operations": "~1.0", - "sebastian/version": "~1.0|~2.0", + "sebastian/version": "~1.0.3|~2.0", "symfony/yaml": "~2.1|~3.0" }, "conflict": { "phpdocumentor/reflection-docblock": "3.0.2" }, + "require-dev": { + "ext-pdo": "*" + }, "suggest": { + "ext-xdebug": "*", "phpunit/php-invoker": "~1.1" }, "bin": [ @@ -713,7 +798,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.5.x-dev" + "dev-master": "5.7.x-dev" } }, "autoload": { @@ -739,27 +824,27 @@ "testing", "xunit" ], - "time": "2016-08-05T04:49:02+00:00" + "time": "2017-05-22T07:42:55+00:00" }, { "name": "phpunit/phpunit-mock-objects", - "version": "3.4.0", + "version": "3.4.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "238d7a2723bce689c79eeac9c7d5e1d623bb9dc2" + "reference": "3ab72b65b39b491e0c011e2e09bb2206c2aa8e24" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/238d7a2723bce689c79eeac9c7d5e1d623bb9dc2", - "reference": "238d7a2723bce689c79eeac9c7d5e1d623bb9dc2", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/3ab72b65b39b491e0c011e2e09bb2206c2aa8e24", + "reference": "3ab72b65b39b491e0c011e2e09bb2206c2aa8e24", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.6 || ^7.0", "phpunit/php-text-template": "^1.2", - "sebastian/exporter": "^1.2" + "sebastian/exporter": "^1.2 || ^2.0" }, "conflict": { "phpunit/phpunit": "<5.4.0" @@ -798,27 +883,27 @@ "mock", "xunit" ], - "time": "2016-10-09T07:01:45+00:00" + "time": "2016-12-08T20:27:08+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe" + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/c36f5e7cfce482fde5bf8d10d41a53591e0198fe", - "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", "shasum": "" }, "require": { - "php": ">=5.6" + "php": "^5.6 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~5" + "phpunit/phpunit": "^5.7 || ^6.0" }, "type": "library", "extra": { @@ -843,26 +928,26 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2016-02-13T06:45:14+00:00" + "time": "2017-03-04T06:30:41+00:00" }, { "name": "sebastian/comparator", - "version": "1.2.0", + "version": "1.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "937efb279bd37a375bcadf584dec0726f84dbf22" + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22", - "reference": "937efb279bd37a375bcadf584dec0726f84dbf22", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", "shasum": "" }, "require": { "php": ">=5.3.3", "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2" + "sebastian/exporter": "~1.2 || ~2.0" }, "require-dev": { "phpunit/phpunit": "~4.4" @@ -907,27 +992,27 @@ "compare", "equality" ], - "time": "2015-07-26T15:48:44+00:00" + "time": "2017-01-29T09:50:25+00:00" }, { "name": "sebastian/diff", - "version": "1.4.1", + "version": "1.4.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", - "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.8" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" }, "type": "library", "extra": { @@ -959,32 +1044,32 @@ "keywords": [ "diff" ], - "time": "2015-12-08T07:14:41+00:00" + "time": "2017-05-22T07:24:03+00:00" }, { "name": "sebastian/environment", - "version": "1.3.8", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", - "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^5.6 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.0" + "phpunit/phpunit": "^5.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1009,25 +1094,25 @@ "environment", "hhvm" ], - "time": "2016-08-18T05:49:44+00:00" + "time": "2016-11-26T07:53:53+00:00" }, { "name": "sebastian/exporter", - "version": "1.2.2", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", - "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", "shasum": "" }, "require": { "php": ">=5.3.3", - "sebastian/recursion-context": "~1.0" + "sebastian/recursion-context": "~2.0" }, "require-dev": { "ext-mbstring": "*", @@ -1036,7 +1121,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1076,7 +1161,7 @@ "export", "exporter" ], - "time": "2016-06-17T09:04:28+00:00" + "time": "2016-11-19T08:54:04+00:00" }, { "name": "sebastian/global-state", @@ -1131,21 +1216,21 @@ }, { "name": "sebastian/object-enumerator", - "version": "1.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "d4ca2fb70344987502567bc50081c03e6192fb26" + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/d4ca2fb70344987502567bc50081c03e6192fb26", - "reference": "d4ca2fb70344987502567bc50081c03e6192fb26", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/1311872ac850040a79c3c058bea3e22d0f09cbb7", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7", "shasum": "" }, "require": { "php": ">=5.6", - "sebastian/recursion-context": "~1.0" + "sebastian/recursion-context": "~2.0" }, "require-dev": { "phpunit/phpunit": "~5" @@ -1153,7 +1238,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1173,20 +1258,20 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2016-01-28T13:25:10+00:00" + "time": "2017-02-18T15:18:39+00:00" }, { "name": "sebastian/recursion-context", - "version": "1.0.2", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "913401df809e99e4f47b27cdd781f4a258d58791" + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791", - "reference": "913401df809e99e4f47b27cdd781f4a258d58791", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", "shasum": "" }, "require": { @@ -1198,7 +1283,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1226,7 +1311,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-11-11T19:50:13+00:00" + "time": "2016-11-19T07:33:16+00:00" }, { "name": "sebastian/resource-operations", @@ -1272,16 +1357,16 @@ }, { "name": "sebastian/version", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5" + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5", - "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", "shasum": "" }, "require": { @@ -1311,20 +1396,20 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-02-04T12:56:52+00:00" + "time": "2016-10-03T07:35:21+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "2.7.0", + "version": "2.9.1", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "571e27b6348e5b3a637b2abc82ac0d01e6d7bbed" + "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/571e27b6348e5b3a637b2abc82ac0d01e6d7bbed", - "reference": "571e27b6348e5b3a637b2abc82ac0d01e6d7bbed", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/dcbed1074f8244661eecddfc2a675430d8d33f62", + "reference": "dcbed1074f8244661eecddfc2a675430d8d33f62", "shasum": "" }, "require": { @@ -1389,29 +1474,35 @@ "phpcs", "standards" ], - "time": "2016-09-01T23:53:02+00:00" + "time": "2017-05-22T02:43:20+00:00" }, { "name": "symfony/yaml", - "version": "v3.1.5", + "version": "v3.3.2", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3" + "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/368b9738d4033c8b93454cb0dbd45d305135a6d3", - "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3", + "url": "https://api.github.com/repos/symfony/yaml/zipball/9752a30000a8ca9f4b34b5227d15d0101b96b063", + "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063", "shasum": "" }, "require": { "php": ">=5.5.9" }, + "require-dev": { + "symfony/console": "~2.8|~3.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "3.3-dev" } }, "autoload": { @@ -1438,24 +1529,24 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-09-25T08:27:07+00:00" + "time": "2017-06-02T22:05:06+00:00" }, { "name": "webmozart/assert", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "bb2d123231c095735130cc8f6d31385a44c7b308" + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/bb2d123231c095735130cc8f6d31385a44c7b308", - "reference": "bb2d123231c095735130cc8f6d31385a44c7b308", + "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", "shasum": "" }, "require": { - "php": "^5.3.3|^7.0" + "php": "^5.3.3 || ^7.0" }, "require-dev": { "phpunit/phpunit": "^4.6", @@ -1464,7 +1555,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "1.3-dev" } }, "autoload": { @@ -1488,7 +1579,7 @@ "check", "validate" ], - "time": "2016-08-09T15:02:57+00:00" + "time": "2016-11-23T20:04:58+00:00" }, { "name": "wp-coding-standards/wpcs", diff --git a/coverage.xml b/coverage.xml deleted file mode 100644 index c0eb55d..0000000 --- a/coverage.xml +++ /dev/null @@ -1,334 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/includes/pb-helpers.php b/inc/helpers/namespace.php similarity index 83% rename from includes/pb-helpers.php rename to inc/helpers/namespace.php index 4ed04d0..0e2b12c 100644 --- a/includes/pb-helpers.php +++ b/inc/helpers/namespace.php @@ -11,19 +11,20 @@ * @return string * @throws \Exception */ -function load_template( $path, array $vars = array() ) { +function load_template( $path, array $vars = [] ) { if ( ! file_exists( $path ) ) { throw new \Exception( "File not found: $path" ); } - ob_start(); extract( $vars ); // @codingStandardsIgnoreLine - include( $path ); - $output = ob_get_contents(); - @ob_end_clean(); - return $output; + if ( is_file( $path ) ) { + ob_start(); + include $path; + return ob_get_clean(); + } + return ''; } // -------------------------------------------------------------------------------------------------------------------- @@ -59,7 +60,7 @@ function install() { $installed_ver = get_option( 'pb_stats_db_version' ); $db_version = get_db_version(); - if ( $installed_ver != $db_version ) { + if ( $installed_ver !== $db_version ) { rename_table(); @@ -90,19 +91,19 @@ function rename_table() { /** @var \wpdb $wpdb */ global $wpdb; - $oldTableName = 'wp_pressbooks_stats_exports'; + $old_table_name = 'wp_pressbooks_stats_exports'; - if ( get_stats_table() == $oldTableName ) { + if ( get_stats_table() === $old_table_name ) { // The old and new table names are the same, ignore return; } // @codingStandardsIgnoreStart - $checkIfOldTableExistsSql = "SELECT 1 FROM {$oldTableName} LIMIT 1 "; + $checkIfOldTableExistsSql = "SELECT 1 FROM {$old_table_name} LIMIT 1 "; $wpdb->get_results( $checkIfOldTableExistsSql, ARRAY_A ); if ( ! $wpdb->last_error ) { // The old hard coded table exists, rename it - $renameTableSql = "RENAME TABLE {$oldTableName} TO " . get_stats_table(); + $renameTableSql = "RENAME TABLE {$old_table_name} TO " . get_stats_table(); $wpdb->query( $renameTableSql ); } // @codingStandardsIgnoreEnd diff --git a/includes/pb-stats.php b/inc/stats/namespace.php similarity index 65% rename from includes/pb-stats.php rename to inc/stats/namespace.php index 3d0cad8..e73f4d5 100644 --- a/includes/pb-stats.php +++ b/inc/stats/namespace.php @@ -1,5 +1,5 @@ insert( \PressbooksStats\Helpers\get_stats_table(), - array( + [ 'user_id' => get_current_user_id(), 'blog_id' => get_current_blog_id(), 'time' => date( 'Y-m-d H:i:s' ), 'export_type' => $export_type, 'theme' => '' . wp_get_theme(), // Stringify by appending to empty string - ), - array( '%d', '%d', '%s', '%s', '%s' ) ); + ], [ '%d', '%d', '%s', '%s', '%s' ] + ); } @@ -31,13 +31,13 @@ function track_export( $export_type ) { */ function init_css_js() { - wp_register_script( 'pb-vip-stats-1', PB_STATS_PLUGIN_URL . 'symbionts/visualize/js/visualize.jQuery.js', array( 'jquery' ) ); + wp_register_script( 'pb-vip-stats-1', PB_STATS_PLUGIN_URL . 'symbionts/visualize/js/visualize.jQuery.js', [ 'jquery' ] ); wp_register_style( 'pb-vip-stats-2', PB_STATS_PLUGIN_URL . 'symbionts/visualize/css/basic.css' ); wp_register_style( 'pb-vip-stats-3', PB_STATS_PLUGIN_URL . 'symbionts/visualize/css/visualize.css' ); wp_register_style( 'pb-vip-stats-4', PB_STATS_PLUGIN_URL . 'symbionts/visualize/css/visualize-light.css' ); - wp_register_script( 'pb-vip-stats-5', PB_STATS_PLUGIN_URL . 'assets/js/graphs.js', array( 'pb-vip-stats-1' ), '20130718' ); - wp_register_style( 'pb-vip-stats-6', PB_STATS_PLUGIN_URL . 'assets/css/stats.css', array(), '20130718' ); + wp_register_script( 'pb-vip-stats-5', PB_STATS_PLUGIN_URL . 'assets/js/graphs.js', [ 'pb-vip-stats-1' ], '20130718' ); + wp_register_style( 'pb-vip-stats-6', PB_STATS_PLUGIN_URL . 'assets/css/stats.css', [], '20130718' ); } @@ -55,10 +55,10 @@ function menu() { if ( $restricted ) { $restricted = maybe_unserialize( $restricted[0]->meta_value ); } else { - $restricted = array(); + $restricted = []; } - if ( ! in_array( $user->ID, $restricted ) ) { + if ( ! in_array( $user->ID, $restricted ) ) { // @codingStandardsIgnoreLine $page = add_menu_page( 'Pressbooks Statistics', 'PB Stats', @@ -69,7 +69,7 @@ function menu() { add_action( 'admin_enqueue_scripts', function ( $hook ) use ( $page ) { - if ( $hook == $page ) { + if ( $hook === $page ) { wp_enqueue_script( 'pb-vip-stats-1' ); wp_enqueue_style( 'pb-vip-stats-2' ); wp_enqueue_style( 'pb-vip-stats-3' ); @@ -83,12 +83,39 @@ function menu() { } +/** + * @return string + */ +function get_admin_page_html_cache_key() { + return 'pb_stats_admin_page_html'; +} + + /** * Echo stats dashboard + * + * @param bool $use_cached_version (optional) */ function display_stats_admin_page() { - $vars = array( + $html = get_site_transient( get_admin_page_html_cache_key() ); + if ( ! empty( $html ) ) { + echo "{$html}"; + } else { + $html = generate_stats_admin_page(); + echo $html; + } +} + +/** + * Generate the stats dashboard + * + * @return string HTML + */ +function generate_stats_admin_page() { + + // Unoptimized SQL ahead! + $vars = [ 'totals' => query_totals(), 'books_exported_today' => query_books_exported( '24 HOUR' ), 'users_exported_today' => query_users_exported( '24 HOUR' ), @@ -100,11 +127,19 @@ function display_stats_admin_page() { 'export_types' => query_export_stats( 'export_type' ), 'export_themes' => query_export_stats( 'theme' ), 'recents' => query_last_100(), - ); + ]; + + $html = \PressbooksStats\Helpers\load_template( PB_STATS_PLUGIN_DIR . 'templates/stats.php', $vars ); - echo \PressbooksStats\Helpers\load_template( PB_STATS_PLUGIN_DIR . '/templates/stats.php', $vars ); + return $html; } +/** + * Cache the stats stats dashboard + */ +function cache_stats_admin_page() { + set_site_transient( get_admin_page_html_cache_key(), generate_stats_admin_page() ); +} // ------------------------------------------------------------------------------------------------------------------- // SQL Helpers @@ -115,30 +150,25 @@ function query_totals() { /** @var \wpdb $wpdb */ global $wpdb; - $foo = array(); + $foo = []; // Sites - $sql = "SELECT COUNT(*) AS total FROM {$wpdb->blogs} "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( "SELECT COUNT(*) AS total FROM {$wpdb->blogs} ", ARRAY_A ); $foo['sites']['total'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT(*) AS total FROM {$wpdb->blogs} WHERE spam = 1 "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( "SELECT COUNT(*) AS total FROM {$wpdb->blogs} WHERE spam = 1 ", ARRAY_A ); $foo['sites']['spam'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT(*) AS total FROM {$wpdb->blogs} WHERE ( deleted = 1 OR archived = '1') AND ( spam = 0 ) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( "SELECT COUNT(*) AS total FROM {$wpdb->blogs} WHERE ( deleted = 1 OR archived = '1') AND ( spam = 0 ) ", ARRAY_A ); $foo['sites']['deactivated'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; // Users - $sql = "SELECT COUNT(*) AS total FROM {$wpdb->users} "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( "SELECT COUNT(*) AS total FROM {$wpdb->users} ", ARRAY_A ); $foo['users']['total'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT(*) AS total FROM {$wpdb->users} WHERE spam = 1 "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( "SELECT COUNT(*) AS total FROM {$wpdb->users} WHERE spam = 1 ", ARRAY_A ); $foo['users']['spam'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; return $foo; @@ -192,7 +222,7 @@ function query_books_exported( $interval, $just_the_count = false ) { GROUP BY {$col} ORDER BY total DESC "; $foo = $wpdb->get_results( $sql, ARRAY_A ); - if ( false == $just_the_count ) { + if ( false === (bool) $just_the_count ) { foreach ( $foo as $key => $val ) { @@ -234,9 +264,9 @@ function query_users_exported( $interval, $just_the_count = false ) { GROUP BY {$col} ORDER BY total DESC "; $foo = $wpdb->get_results( $sql, ARRAY_A ); - if ( false == $just_the_count ) { + if ( false === (bool) $just_the_count ) { - $is_new = array(); + $is_new = []; $sql = "SELECT ID FROM {$wpdb->users} WHERE user_registered > DATE_SUB(NOW(), INTERVAL 24 HOUR)"; $bar = $wpdb->get_results( $sql, ARRAY_A ); @@ -266,8 +296,8 @@ function query_export_stats( $col ) { $table = \PressbooksStats\Helpers\get_stats_table(); $time = 'time'; - $foo = array(); - $bar = array(); + $foo = []; + $bar = []; // today, week, month, quarter @@ -293,19 +323,23 @@ function query_export_stats( $col ) { foreach ( $foo as $range => $val ) { foreach ( $val as $val2 ) { - $bar[ $val2[ $col ] ][ $range ] = @$bar[ $val2[ $col ] ][ $range ] + $val2['total']; + $bar[ $val2[ $col ] ][ $range ] = @$bar[ $val2[ $col ] ][ $range ] + $val2['total']; // @codingStandardsIgnoreLine } } // Add missing zeros foreach ( $bar as $key => $val ) { - if ( ! isset( $val['today'] ) ) { $bar[ $key ]['today'] = 0; + if ( ! isset( $val['today'] ) ) { + $bar[ $key ]['today'] = 0; } - if ( ! isset( $val['week'] ) ) { $bar[ $key ]['week'] = 0; + if ( ! isset( $val['week'] ) ) { + $bar[ $key ]['week'] = 0; } - if ( ! isset( $val['month'] ) ) { $bar[ $key ]['month'] = 0; + if ( ! isset( $val['month'] ) ) { + $bar[ $key ]['month'] = 0; } - if ( ! isset( $val['quarter'] ) ) { $bar[ $key ]['quarter'] = 0; + if ( ! isset( $val['quarter'] ) ) { + $bar[ $key ]['quarter'] = 0; } } @@ -317,77 +351,54 @@ function query_export_stats( $col ) { function query_sites_stats( $col ) { - /** - * wp_blogs - * Deactivate: Flags deleted db field, message is displayed on the front side, can undo - * Archive: Flags archived db field, message is displayed on the front side, can undo - * Spam: Flags spam db field, message is displayed on the front side, can undo - * Delete: Drops tables and rm dirs and files - * User Delete Blog: Drops tables and rm dirs and files - */ - /** @var \wpdb $wpdb */ global $wpdb; - $table = "{$wpdb->blogs}"; $time = 'registered'; - - $foo = array(); + $foo = []; // Registered - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > DATE_SUB(NOW(), INTERVAL 24 HOUR) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE %s > DATE_SUB(NOW(), INTERVAL 24 HOUR) ", $col, $time ), ARRAY_A ); $foo['registered']['today'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > NOW() - INTERVAL 1 WEEK "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE %s > NOW() - INTERVAL 1 WEEK ", $col, $time ), ARRAY_A ); $foo['registered']['week'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > NOW() - INTERVAL 1 MONTH "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE %s > NOW() - INTERVAL 1 MONTH ", $col, $time ), ARRAY_A ); $foo['registered']['month'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > NOW() - INTERVAL 3 MONTH "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE %s > NOW() - INTERVAL 3 MONTH ", $col, $time ), ARRAY_A ); $foo['registered']['quarter'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; // Active $time = 'last_updated'; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > DATE_SUB(NOW(), INTERVAL 24 HOUR) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE %s > DATE_SUB(NOW(), INTERVAL 24 HOUR) ", $col, $time ), ARRAY_A ); $foo['active']['today'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > NOW() - INTERVAL 1 WEEK "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE %s > NOW() - INTERVAL 1 WEEK ", $col, $time ), ARRAY_A ); $foo['active']['week'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > NOW() - INTERVAL 1 MONTH "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE %s > NOW() - INTERVAL 1 MONTH ", $col, $time ), ARRAY_A ); $foo['active']['month'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > NOW() - INTERVAL 3 MONTH "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE %s > NOW() - INTERVAL 3 MONTH ", $col, $time ), ARRAY_A ); $foo['active']['quarter'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; // Spam - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE ( spam = 1 ) AND ( `{$time}` > DATE_SUB(NOW(), INTERVAL 24 HOUR)) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE ( spam = 1 ) AND ( %s > DATE_SUB(NOW(), INTERVAL 24 HOUR)) ", $col, $time ), ARRAY_A ); $foo['spam']['today'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE ( spam = 1 ) AND ( `{$time}` > NOW() - INTERVAL 1 WEEK ) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE ( spam = 1 ) AND ( %s > NOW() - INTERVAL 1 WEEK ) ", $col, $time ), ARRAY_A ); $foo['spam']['week'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE ( spam = 1 ) AND ( `{$time}` > NOW() - INTERVAL 1 MONTH ) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE ( spam = 1 ) AND ( %s > NOW() - INTERVAL 1 MONTH ) ", $col, $time ), ARRAY_A ); $foo['spam']['month'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE ( spam = 1 ) AND ( `{$time}` > NOW() - INTERVAL 3 MONTH ) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->blogs} WHERE ( spam = 1 ) AND ( %s > NOW() - INTERVAL 3 MONTH ) ", $col, $time ), ARRAY_A ); $foo['spam']['quarter'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; return $foo; @@ -396,60 +407,38 @@ function query_sites_stats( $col ) { function query_user_stats( $col ) { - /** - * wp_users - * fields we care about: user_registered, spam, deleted - */ - - /** - * wp_usermeta - * a user can have access to more than one blog. There are two elements in the usermeta table to look into: - * 'primary_blog' - As the key_name implies this is the user's primary blog. Will only contain one blog ID. - * A given user may have multiple 'wp_XX_capabilities' rows where 'XX' is the blog ID. - */ - /** @var \wpdb $wpdb */ global $wpdb; - $table = "{$wpdb->users}"; $time = 'user_registered'; - - $foo = array(); + $foo = []; // Registered - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > DATE_SUB(NOW(), INTERVAL 24 HOUR) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->users} WHERE %s > DATE_SUB(NOW(), INTERVAL 24 HOUR) ", $col, $time ), ARRAY_A ); $foo['registered']['today'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > NOW() - INTERVAL 1 WEEK "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->users} WHERE %s > NOW() - INTERVAL 1 WEEK ", $col, $time ), ARRAY_A ); $foo['registered']['week'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > NOW() - INTERVAL 1 MONTH "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->users} WHERE %s > NOW() - INTERVAL 1 MONTH ", $col, $time ), ARRAY_A ); $foo['registered']['month'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE `{$time}` > NOW() - INTERVAL 3 MONTH "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->users} WHERE %s > NOW() - INTERVAL 3 MONTH ", $col, $time ), ARRAY_A ); $foo['registered']['quarter'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; // Spam - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE ( spam = 1 ) AND ( `{$time}` > DATE_SUB(NOW(), INTERVAL 24 HOUR)) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->users} WHERE ( spam = 1 ) AND ( %s > DATE_SUB(NOW(), INTERVAL 24 HOUR)) ", $col, $time ), ARRAY_A ); $foo['spam']['today'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE ( spam = 1 ) AND ( `{$time}` > NOW() - INTERVAL 1 WEEK ) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->users} WHERE ( spam = 1 ) AND ( %s > NOW() - INTERVAL 1 WEEK ) ", $col, $time ), ARRAY_A ); $foo['spam']['week'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE ( spam = 1 ) AND ( `{$time}` > NOW() - INTERVAL 1 MONTH ) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->users} WHERE ( spam = 1 ) AND ( %s > NOW() - INTERVAL 1 MONTH ) ", $col, $time ), ARRAY_A ); $foo['spam']['month'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; - $sql = "SELECT COUNT($col) AS total FROM {$table} WHERE ( spam = 1 ) AND ( `{$time}` > NOW() - INTERVAL 3 MONTH ) "; - $tmp = $wpdb->get_results( $sql, ARRAY_A ); + $tmp = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(%s) AS total FROM {$wpdb->users} WHERE ( spam = 1 ) AND ( %s > NOW() - INTERVAL 3 MONTH ) ", $col, $time ), ARRAY_A ); $foo['spam']['quarter'] = isset( $tmp[0]['total'] ) ? $tmp[0]['total'] : 0; return $foo; @@ -458,16 +447,10 @@ function query_user_stats( $col ) { function users_with_x_or_more_books( $x ) { - $transient = "users_with_{$x}_or_more_books"; - $foo = get_transient( $transient ); - if ( false !== $foo ) { - return $foo; // Return cached copy - } - /** @var \wpdb $wpdb */ global $wpdb; - $foo = array(); + $foo = []; $sql = "SELECT {$wpdb->usermeta}.user_id, {$wpdb->users}.user_login AS username, count({$wpdb->usermeta}.meta_key) AS total FROM {$wpdb->usermeta} INNER JOIN {$wpdb->users} ON {$wpdb->usermeta}.user_id = {$wpdb->users}.ID @@ -482,17 +465,14 @@ function users_with_x_or_more_books( $x ) { $sql = 'SELECT `time` FROM ' . \PressbooksStats\Helpers\get_stats_table() . ' WHERE user_id = ' . absint( $val['user_id'] ) . ' ORDER BY `time` DESC LIMIT 1 '; $tmp2 = $wpdb->get_results( $sql, ARRAY_A ); - $foo[] = array( + $foo[] = [ 'username' => $val['username'], 'last_export' => ( isset( $tmp2[0]['time'] ) ? date( 'Y-m-d', strtotime( $tmp2[0]['time'] ) ) : '!' ), - ); + ]; } } - $foo = wp_list_sort( $foo, array( 'last_export' => 'DESC' ) ); - - set_transient( $transient, $foo, 60 * 60 * 12 ); + $foo = wp_list_sort( $foo, [ 'last_export' => 'DESC' ] ); return $foo; } -// @codingStandardsIgnoreEnd diff --git a/phpcs.ruleset.xml b/phpcs.ruleset.xml new file mode 100644 index 0000000..84d43d9 --- /dev/null +++ b/phpcs.ruleset.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /inc/admin/class-catalog-list-table.php + /inc/admin/class-network-managers-list-table.php + /api/endpoints/controller/* + + + + + /pressbooks-stats.php + + + + + /inc/stats/namespace.php + + + diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 8d349a6..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - Pressbooks Coding Standards - - - - - - - - - - tests/ - - symbionts/ - - vendor/ - - - - - - - - - - - - diff --git a/phpunit.xml b/phpunit.xml index a36f779..cc8fc04 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -16,7 +16,7 @@ - ./includes + ./inc diff --git a/pressbooks-stats.php b/pressbooks-stats.php index 5b89c33..9a5c1f6 100644 --- a/pressbooks-stats.php +++ b/pressbooks-stats.php @@ -2,7 +2,7 @@ /* Plugin Name: Pressbooks Stats Description: Pressbooks plugin which provides some basic activity statistics for a Pressbooks network. -Version: 1.3.0 +Version: 1.4.0 Author: BookOven Inc. */ @@ -10,11 +10,10 @@ // Check minimum requirements // ------------------------------------------------------------------------------------------------------------------- -if ( ! function_exists( 'pb_meets_minimum_requirements' ) && ! @include_once( WP_PLUGIN_DIR . '/pressbooks/compatibility.php' ) ) { - add_action( 'admin_notices', function () { +if ( ! function_exists( 'pb_meets_minimum_requirements' ) && ! @include_once( WP_PLUGIN_DIR . '/pressbooks/compatibility.php' ) ) { // @codingStandardsIgnoreLine + return add_action( 'admin_notices', function () { echo '

' . __( 'Cannot find Pressbooks install.', 'pressbooks-stats' ) . '

'; } ); - return; } elseif ( ! pb_meets_minimum_requirements() ) { return; } @@ -35,30 +34,14 @@ // Class autoloader // ------------------------------------------------------------------------------------------------------------------- -function _pressbooks_stats_autoload( $class_name ) { - - $prefix = 'PressbooksStats\\'; - $len = strlen( $prefix ); - if ( strncmp( $prefix, $class_name, $len ) !== 0 ) { - // Ignore classes not in our namespace - return; - } - - $parts = explode( '\\', strtolower( $class_name ) ); - array_shift( $parts ); - $class_file = 'class-pb-' . str_replace( '_', '-', array_pop( $parts ) ) . '.php'; - $path = count( $parts ) ? implode( '/', $parts ) . '/' : ''; - require( PB_STATS_PLUGIN_DIR . 'includes/' . $path . $class_file ); -} - -spl_autoload_register( '_pressbooks_stats_autoload' ); +\HM\Autoloader\register_class_path( 'PressbooksStats', __DIR__ . '/inc' ); // ------------------------------------------------------------------------------------------------------------------- // Requires // ------------------------------------------------------------------------------------------------------------------- -require( PB_STATS_PLUGIN_DIR . 'includes/pb-helpers.php' ); -require( PB_STATS_PLUGIN_DIR . 'includes/pb-stats.php' ); +require( PB_STATS_PLUGIN_DIR . 'inc/helpers/namespace.php' ); +require( PB_STATS_PLUGIN_DIR . 'inc/stats/namespace.php' ); // ------------------------------------------------------------------------------------------------------------------- // Hooks diff --git a/templates/stats.php b/templates/stats.php index a931357..3be022a 100644 --- a/templates/stats.php +++ b/templates/stats.php @@ -147,8 +147,6 @@ - -
Users who exported in the last 24h