diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 849c501..90cf931 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -6,4 +6,4 @@ checks: code_rating: true duplication: true filter: - paths: [source/*, tests/*] + paths: [src/*, tests/*] diff --git a/changelog.md b/changelog.md deleted file mode 100644 index 77a9340..0000000 --- a/changelog.md +++ /dev/null @@ -1,5 +0,0 @@ -# Changelog - -## 0.1.0 - -First release. diff --git a/code-of-conduct.md b/code-of-conduct.md new file mode 100644 index 0000000..ae45a0e --- /dev/null +++ b/code-of-conduct.md @@ -0,0 +1,22 @@ +# Code of Conduct + +As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, such as physical or electronic addresses, without explicit permission +* Other unethical or unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. + +This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) diff --git a/composer.json b/composer.json index 0a785d4..a70dbba 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ ] }, "require-dev": { - "php": ">=5.5.0", "phpunit/phpunit": "4.*" }, "autoload-dev": { diff --git a/composer.lock b/composer.lock index 21ddbef..ceb78e4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "8ee12d6427f92c84e230c17669ef606d", + "hash": "03ff8205638438c08aa1607992fb2aec", "packages": [], "packages-dev": [ { @@ -63,16 +63,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "2.0.11", + "version": "2.0.13", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7" + "reference": "0e7d2eec5554f869fa7a4ec2d21e4b37af943ea5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/53603b3c995f5aab6b59c8e08c3a663d2cc810b7", - "reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0e7d2eec5554f869fa7a4ec2d21e4b37af943ea5", + "reference": "0e7d2eec5554f869fa7a4ec2d21e4b37af943ea5", "shasum": "" }, "require": { @@ -124,7 +124,7 @@ "testing", "xunit" ], - "time": "2014-08-31 06:33:04" + "time": "2014-12-03 06:41:44" }, { "name": "phpunit/php-file-iterator", @@ -310,16 +310,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.3.4", + "version": "4.4.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "23e4e0310f037aae873cc81b8658dbbb82878f71" + "reference": "bbe7bcb83b6ec1a9eaabbe1b70d4795027c53ee0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/23e4e0310f037aae873cc81b8658dbbb82878f71", - "reference": "23e4e0310f037aae873cc81b8658dbbb82878f71", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/bbe7bcb83b6ec1a9eaabbe1b70d4795027c53ee0", + "reference": "bbe7bcb83b6ec1a9eaabbe1b70d4795027c53ee0", "shasum": "" }, "require": { @@ -336,8 +336,9 @@ "phpunit/phpunit-mock-objects": "~2.3", "sebastian/comparator": "~1.0", "sebastian/diff": "~1.1", - "sebastian/environment": "~1.0", + "sebastian/environment": "~1.1", "sebastian/exporter": "~1.0", + "sebastian/global-state": "~1.0", "sebastian/version": "~1.0", "symfony/yaml": "~2.0" }, @@ -350,7 +351,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.3.x-dev" + "dev-master": "4.4.x-dev" } }, "autoload": { @@ -359,10 +360,6 @@ ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "", - "../../symfony/yaml/" - ], "license": [ "BSD-3-Clause" ], @@ -374,13 +371,13 @@ } ], "description": "The PHP Unit Testing framework.", - "homepage": "http://www.phpunit.de/", + "homepage": "https://phpunit.de/", "keywords": [ "phpunit", "testing", "xunit" ], - "time": "2014-10-22 11:43:12" + "time": "2014-12-05 06:49:03" }, { "name": "phpunit/phpunit-mock-objects", @@ -439,16 +436,16 @@ }, { "name": "sebastian/comparator", - "version": "1.0.1", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef" + "reference": "c484a80f97573ab934e37826dba0135a3301b26a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", - "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/c484a80f97573ab934e37826dba0135a3301b26a", + "reference": "c484a80f97573ab934e37826dba0135a3301b26a", "shasum": "" }, "require": { @@ -462,7 +459,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.1.x-dev" } }, "autoload": { @@ -499,7 +496,7 @@ "compare", "equality" ], - "time": "2014-05-11 23:00:21" + "time": "2014-11-16 21:32:38" }, { "name": "sebastian/diff", @@ -555,16 +552,16 @@ }, { "name": "sebastian/environment", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d" + "reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/0d9bf79554d2a999da194a60416c15cf461eb67d", - "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6e6c71d918088c251b181ba8b3088af4ac336dd7", + "reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7", "shasum": "" }, "require": { @@ -601,7 +598,7 @@ "environment", "hhvm" ], - "time": "2014-10-22 06:38:05" + "time": "2014-10-25 08:00:45" }, { "name": "sebastian/exporter", @@ -668,6 +665,57 @@ ], "time": "2014-09-10 00:51:36" }, + { + "name": "sebastian/global-state", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2014-10-06 09:23:50" + }, { "name": "sebastian/version", "version": "1.0.3", @@ -705,17 +753,17 @@ }, { "name": "symfony/yaml", - "version": "v2.5.6", + "version": "v2.6.1", "target-dir": "Symfony/Component/Yaml", "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726" + "reference": "3346fc090a3eb6b53d408db2903b241af51dcb20" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/2d9f527449cabfa8543dd7fa3a466d6ae83d6726", - "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/3346fc090a3eb6b53d408db2903b241af51dcb20", + "reference": "3346fc090a3eb6b53d408db2903b241af51dcb20", "shasum": "" }, "require": { @@ -724,7 +772,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -748,7 +796,7 @@ ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com", - "time": "2014-10-01 05:50:18" + "time": "2014-12-02 20:19:20" } ], "aliases": [], @@ -758,7 +806,5 @@ "platform": { "php": ">=5.4.0" }, - "platform-dev": { - "php": ">=5.5.0" - } + "platform-dev": [] } diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..32334e2 --- /dev/null +++ b/contributing.md @@ -0,0 +1,3 @@ +# Contributing + +Contributions are welcome! Create an issue, explaining a bug or proposal. Submit pull requests if you feel brave. Speak to me on [Twitter](https://twitter.com/assertchris). diff --git a/license.md b/license.md index dd55b9c..823fc32 100644 --- a/license.md +++ b/license.md @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2014 Christopher Pitt +Copyright (c) 2015 Christopher Pitt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/phpunit.xml b/phpunit.xml index c51473a..ba09734 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -17,7 +17,7 @@ - source + src diff --git a/readme.md b/readme.md index 5a45faa..b1c13b0 100644 --- a/readme.md +++ b/readme.md @@ -19,15 +19,15 @@ TypeFunctions\isBoolean("false"); // false Functions: -- `isNumber` -- `isBoolean` -- `isNull` -- `isObject` -- `isFunction` -- `isExpression` -- `isString` -- `isResource` -- `getType` +- `isNumber(mixed $variable) → bool` +- `isBoolean(mixed $variable) → bool` +- `isNull(mixed $variable) → bool` +- `isObject(mixed $variable) → bool` +- `isFunction(mixed $variable) → bool` +- `isExpression(mixed $variable) → bool` +- `isString(mixed $variable) → bool` +- `isResource(mixed $variable) → bool` +- `getType(mixed $variable) → string` Caveats: diff --git a/src/TypeFunctions.php b/src/TypeFunctions.php index 1f78390..2759e6a 100644 --- a/src/TypeFunctions.php +++ b/src/TypeFunctions.php @@ -85,6 +85,16 @@ function isResource($variable) return is_resource($variable); } +/** + * @param mixed $variable + * + * @return bool + */ +function isArray($variable) +{ + return is_array($variable); +} + /** * @param mixed $variable * @@ -93,22 +103,24 @@ function isResource($variable) function getType($variable) { $functions = [ - "isNumber" => "number", - "isBoolean" => "boolean", - "isNull" => "null", - "isObject" => "object", - "isFunction" => "function", + "isNumber" => "number", + "isBoolean" => "boolean", + "isNull" => "null", + "isObject" => "object", + "isFunction" => "function", "isExpression" => "expression", - "isString" => "string", - "isResource" => "resource" + "isString" => "string", + "isResource" => "resource", + "isArray" => "array" ]; $result = "unknown"; foreach ($functions as $function => $type) { - $qualified = "TypedPHP\\Functions\\TypeFunctions\\{$function}"; + $namespace = "TypedPHP\\Functions\\TypeFunctions\\"; + $function = $namespace . $function; - if ($qualified($variable)) { + if ($function($variable)) { $result = $type; break; } diff --git a/tests/Test.php b/tests/Test.php index 76b70c1..8a97a9d 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -6,5 +6,4 @@ class Test extends PHPUnit_Framework_TestCase { - } diff --git a/tests/TypeFunctionTest.php b/tests/TypeFunctionTest.php index 9bc96ac..76b4001 100644 --- a/tests/TypeFunctionTest.php +++ b/tests/TypeFunctionTest.php @@ -6,9 +6,6 @@ class TypeFunctionTest extends Test { - /** - * @test - */ public function testIsNumber() { $this->assertTrue(TypeFunctions\isNumber(0)); @@ -20,9 +17,6 @@ public function testIsNumber() $this->assertFalse(TypeFunctions\isNumber(false)); } - /** - * @test - */ public function testIsBoolean() { $this->assertTrue(TypeFunctions\isBoolean(true)); @@ -34,9 +28,6 @@ public function testIsBoolean() $this->assertFalse(TypeFunctions\isBoolean(0)); } - /** - * @test - */ public function testIsNull() { $this->assertTrue(TypeFunctions\isNull(null)); @@ -46,9 +37,6 @@ public function testIsNull() $this->assertFalse(TypeFunctions\isNull(0)); } - /** - * @test - */ public function testIsObject() { $this->assertTrue(TypeFunctions\isObject($this)); @@ -60,9 +48,6 @@ public function testIsObject() $this->assertFalse(TypeFunctions\isObject($function)); } - /** - * @test - */ public function testIsFunction() { $function = function () { @@ -75,9 +60,6 @@ public function testIsFunction() $this->assertFalse(TypeFunctions\isFunction("is_callable")); } - /** - * @test - */ public function testIsExpression() { $this->assertTrue(TypeFunctions\isExpression("[a-z]")); @@ -85,9 +67,6 @@ public function testIsExpression() $this->assertFalse(TypeFunctions\isExpression("hello")); } - /** - * @test - */ public function testIsString() { $this->assertTrue(TypeFunctions\isString("hello")); @@ -95,9 +74,6 @@ public function testIsString() $this->assertFalse(TypeFunctions\isString("[a-z]")); } - /** - * @test - */ public function testIsResource() { $file = fopen(__FILE__, "r"); @@ -109,9 +85,13 @@ public function testIsResource() fclose($file); } - /** - * @test - */ + public function testIsArray() + { + $this->assertTrue(TypeFunctions\isArray(["foo", "bar"])); + + $this->assertFalse(TypeFunctions\isArray("foo")); + } + public function testGetType() { $file = fopen(__FILE__, "r"); @@ -121,14 +101,15 @@ public function testGetType() }; $types = [ - "number" => 1.5, - "boolean" => true, - "null" => null, - "object" => $this, - "function" => $function, + "number" => 1.5, + "boolean" => true, + "null" => null, + "object" => $this, + "function" => $function, "expression" => "[a-z]", - "string" => "hello", - "resource" => $file + "string" => "hello", + "resource" => $file, + "array" => ["foo", "bar"] ]; foreach ($types as $type => $variable) {