-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 431036b
Showing
82 changed files
with
3,871 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
root = true | ||
|
||
[*] | ||
|
||
end_of_line = lf | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = false | ||
|
||
[*.php] | ||
|
||
end_of_line = lf | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/tests export-ignore | ||
/examples export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/phpcs.xml.dist export-ignore | ||
/captainhook.json export-ignore | ||
/.travis.yml export-ignore | ||
/ruleset.xml export-ignore | ||
/.editorconfig export-ignore | ||
/phpstan.neon export-ignore | ||
/psalm.xml export-ignore | ||
/psalm-baseline.xml export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/.idea | ||
/composer.lock | ||
/vendor | ||
/.phpunit* | ||
/tests/_output | ||
/tests/_reports | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
env: | ||
global: | ||
- CC_TEST_REPORTER_ID=c04f7d15abce0dd4c367dfd8fb1828c95ba09a9400f2fd506b9934fb38060b93 | ||
- GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi) | ||
language: php | ||
php: | ||
- '7.2' | ||
- '7.3' | ||
|
||
before_script: | ||
- composer self-update | ||
- composer install --prefer-source --no-interaction --dev | ||
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter | ||
- chmod +x ./cc-test-reporter | ||
- ./cc-test-reporter before-build | ||
|
||
script: | ||
- vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml | ||
- vendor/bin/phpstan analyse src --level=7 | ||
- vendor/bin/psalm --show-info=false | ||
- vendor/bin/phpcs --standard=ruleset.xml --extensions=php src tests | ||
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build -t clover --exit-code $TRAVIS_TEST_RESULT; fi | ||
|
||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Andreas Leathley | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Squirrel Strings | ||
================ | ||
|
||
[![Build Status](https://img.shields.io/travis/com/squirrelphp/strings.svg)](https://travis-ci.com/squirrelphp/strings) [![Test Coverage](https://api.codeclimate.com/v1/badges/780aeeff88d9a49b2d2a/test_coverage)](https://codeclimate.com/github/squirrelphp/strings/test_coverage) ![PHPStan](https://img.shields.io/badge/style-level%207-success.svg?style=flat-round&label=phpstan) [![Packagist Version](https://img.shields.io/packagist/v/squirrelphp/strings.svg?style=flat-round)](https://packagist.org/packages/squirrelphp/strings) [![PHP Version](https://img.shields.io/packagist/php-v/squirrelphp/strings.svg)](https://packagist.org/packages/squirrelphp/strings) [![Software License](https://img.shields.io/badge/license-MIT-success.svg?style=flat-round)](LICENSE) | ||
|
||
Handles common string operations in applications: | ||
|
||
- Filter a string (remove newlines, remove excess spaces, wrap long words, etc.) | ||
- Generate a random string with a set of characters | ||
- Condense a number into a string, and convert back from a string to a number | ||
- Process an URL and modify it in a safe way (convert to relative URL, change parts of it, etc.) | ||
|
||
Filter | ||
------ | ||
|
||
Filters a string according to specific criterias. Each filter does exactly one thing (ideally) so they can be combined depending on how an input needs to be changed / processed. | ||
|
||
Additional filters can easily be defined - for example to process custom tags. This library has some basic useful filters which can be used. | ||
|
||
Random | ||
------ | ||
|
||
Generates random strings according to a list of possible characters which can be used. | ||
|
||
With the two included classes (one with unicode support, one for ASCII-only) it is easy to define a random generator with your own set of characters which should be allowed to appear in a random string. These are sensible values: | ||
|
||
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" for 62 possible values per character, each can be A-Z, a-z or 0-9 and these values are very safe to use in applications (no special characters, only alphanumeric) | ||
- "abcdefghijklmnopqrstuvwxyz0123456789" for 36 possible values per character, same as above except this is the case insensitive version, for when there should be no difference between "A" and "a" (for example) | ||
- "234579ACDEFGHKMNPQRSTUVWXYZ" or "234579acdefghkmnpqrstuvwxyz" for 27 read-friendly uppercase or lowercase characters: if a person has to enter a code it is good to avoid characters which are very similar and easily confusable, like 0 (number zero) and O (letter), or 8 (number eight) and B (letter) | ||
|
||
Defining your own range of possible characters is easy, and even unicode characters can be used. | ||
|
||
Condense | ||
-------- | ||
|
||
Convert an integer to a string with a given "character set" - this way we can encode an integer to condense it (so an integer with 8 numbers is now only a 4-character-string) and later convert it back when needed. | ||
|
||
The main use case are tokens in URLs, so less space is needed, as even large numbers become short strings if you use 36 or 62 values per character: with 62 possible characters ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") a string which is three characters long can cover numbers up to 238'328, with five characters you can cover numbers up to 916'132'832. | ||
|
||
A side benefit of condensing is that it becomes less obvious an integer is used - tokens just look random and do not divulge their intent. | ||
|
||
Defining your own range of possible characters is easy, and even unicode characters can be used. | ||
|
||
URL | ||
--- | ||
|
||
The URL class accepts an URL in the constructor and then lets you get or change certain parts of the URL to do the following: | ||
|
||
- Get scheme, host, path, query string and specific query string variables | ||
- Change an absolute URL to a relative URL | ||
- Change scheme, host, path and query string | ||
- Replace query string variables, or add/remove them | ||
|
||
This can be used to easily build or change your URLs, or to sanitize certain parts of a given URL, for example when redirecting: use the relative URL instead of the absolute URL to avoid malicious redirecting to somewhere outside of your control. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"commit-msg": { | ||
"enabled": true, | ||
"actions": [ | ||
{ | ||
"action": "\\CaptainHook\\App\\Hook\\Message\\Action\\Beams", | ||
"options": { | ||
"subjectLength": 50, | ||
"bodyLineLength": 72 | ||
}, | ||
"conditions": [] | ||
} | ||
] | ||
}, | ||
"pre-push": { | ||
"enabled": false, | ||
"actions": [] | ||
}, | ||
"pre-commit": { | ||
"enabled": true, | ||
"actions": [ | ||
{ | ||
"action": "\\CaptainHook\\App\\Hook\\PHP\\Action\\Linting", | ||
"options": [], | ||
"conditions": [] | ||
}, | ||
{ | ||
"action": "vendor/bin/phpunit", | ||
"options": [], | ||
"conditions": [] | ||
}, | ||
{ | ||
"action": "vendor/bin/phpstan analyse src --level=7", | ||
"options": [], | ||
"conditions": [] | ||
}, | ||
{ | ||
"action": "vendor/bin/psalm", | ||
"options": [], | ||
"conditions": [] | ||
}, | ||
{ | ||
"action": "vendor/bin/phpcs --standard=ruleset.xml --extensions=php --cache src tests", | ||
"options": [], | ||
"conditions": [] | ||
} | ||
] | ||
}, | ||
"prepare-commit-msg": { | ||
"enabled": false, | ||
"actions": [] | ||
}, | ||
"post-commit": { | ||
"enabled": false, | ||
"actions": [] | ||
}, | ||
"post-merge": { | ||
"enabled": false, | ||
"actions": [] | ||
}, | ||
"post-checkout": { | ||
"enabled": false, | ||
"actions": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"name": "squirrelphp/strings", | ||
"type": "library", | ||
"description": "Common string operations in PHP: filter a string, generate a random string, condense an integer into a string, and modify URLs", | ||
"keywords": [ | ||
"php", | ||
"strings", | ||
"filters", | ||
"random", | ||
"urls" | ||
], | ||
"homepage": "https://github.com/squirrelphp/strings", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Andreas Leathley", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.2" | ||
}, | ||
"require-dev": { | ||
"ext-intl": "*", | ||
"ext-mbstring": "*", | ||
"captainhook/plugin-composer": "^4.0", | ||
"diablomedia/phpunit-pretty-printer": "^4.0", | ||
"mockery/mockery": "^1.0", | ||
"phpstan/phpstan": "^0.11.5", | ||
"phpunit/phpunit": "^8.0", | ||
"slevomat/coding-standard": "^5.0", | ||
"squizlabs/php_codesniffer": "^3.2", | ||
"vimeo/psalm": "^3.2", | ||
"doctrine/annotations": "^1.5", | ||
"twig/twig": "^2.0", | ||
"symfony/form": "^4.2", | ||
"symfony/http-foundation": "^4.2" | ||
}, | ||
"suggest": { | ||
"squirrelphp/strings-bundle": "Symfony integration of squirrelphp/strings" | ||
}, | ||
"config": { | ||
"sort-packages": false | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Squirrel\\Strings\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Squirrel\\Strings\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"phpstan": "vendor/bin/phpstan analyse src --level=7", | ||
"psalm": "vendor/bin/psalm --show-info=false", | ||
"psalm_base": "vendor/bin/psalm --set-baseline=psalm-baseline.xml", | ||
"phpunit": "vendor/bin/phpunit --colors=always", | ||
"phpcs": "vendor/bin/phpcs --standard=ruleset.xml --extensions=php --cache src tests", | ||
"phpcsfix": "vendor/bin/phpcbf --standard=ruleset.xml --extensions=php --cache src tests", | ||
"codecoverage": "vendor/bin/phpunit --coverage-html tests/_reports" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.3/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="vendor/autoload.php" | ||
> | ||
<testsuites> | ||
<testsuite name="Unit Tests"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<psalm | ||
totallyTyped="false" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://getpsalm.org/schema/config" | ||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" | ||
> | ||
<projectFiles> | ||
<directory name="src" /> | ||
<ignoreFiles> | ||
<directory name="vendor" /> | ||
</ignoreFiles> | ||
</projectFiles> | ||
</psalm> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="IQ"> | ||
<description>PSR2 with some additional useful sniffs</description> | ||
|
||
<!-- Include the whole PSR-2 standard except for line length --> | ||
<rule ref="PSR2"> | ||
<exclude name="Generic.Files.LineLength"/> | ||
</rule> | ||
|
||
|
||
<config name="installed_paths" value="../../slevomat/coding-standard"/> | ||
|
||
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/> | ||
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch"/> | ||
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEmpty"/> | ||
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"> | ||
<properties> | ||
<property name="searchAnnotations" value="true"/> | ||
</properties> | ||
</rule> | ||
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/> | ||
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/> | ||
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/> | ||
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/> | ||
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/> | ||
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/> | ||
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/> | ||
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations"> | ||
<properties> | ||
<property name="forbiddenAnnotations" type="array"> | ||
<element value="@author"/> | ||
<element value="@created"/> | ||
<element value="@copyright"/> | ||
<element value="@license"/> | ||
<element value="@package"/> | ||
<element value="@version"/> | ||
</property> | ||
</properties> | ||
</rule> | ||
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Squirrel\Strings\Annotation; | ||
|
||
use Doctrine\Common\Annotations\Annotation; | ||
|
||
/** | ||
* @Annotation | ||
* @Target({"PROPERTY"}) | ||
*/ | ||
class StringFilter | ||
{ | ||
/** | ||
* @var mixed Filter names which should be executed, either a string or array | ||
*/ | ||
public $names = []; | ||
} |
Oops, something went wrong.