diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..baefe38 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,28 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "" +labels: bug +assignees: vdhicts + +--- + +## Describe the bug + +A clear and concise description of what the bug is. + +## Reproduction + +Steps to reproduce the behavior. + +## Expected behavior + +A clear and concise description of what you expected to happen. + +## Actual behavior + +Describe the behavior as it is right now. + +## Additional information + +Anything else you want to provide. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..afed919 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,16 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "" +labels: feature +assignees: vdhicts + +--- + +## Goal + +A clear and concise description of what the problem is. Ex. I think this could be easier when... + +## Additional information + +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..e7e36af --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,3 @@ +# Changes + +Provide a summary of your changes. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..726f4b5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI + +on: [push] + +jobs: + tests: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Setup PHP + uses: shivammathur/setup-php@v1 + with: + php-version: '7.4' + extensions: mbstring, intl + + - name: Install Dependencies + run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress + + - name: Execute tests (Unit and Feature tests) via PHPUnit + run: | + vendor/bin/phpunit + + - name: Execute static analysis + run: | + vendor/bin/psalm + diff --git a/.gitignore b/.gitignore index e66a26f..a5bc3c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,151 +1,5 @@ -# Based on https://github.com/github/gitignore/tree/master/Global - -################################################################################ -# -# Ignore all dot-files and dot-folders, except .htaccess and .gitignore -# -################################################################################ -.* -!/.gitignore -!/.htaccess - -################################################################################ -# -# JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion -# -################################################################################ -*.iml -.idea/ - -## File-based project format: -*.ipr -*.iws - -# Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties - -################################################################################ -# -# Netbeans -# -################################################################################ - -nbproject/ -build/ -nbbuild/ -dist/ -nbdist/ -nbactions.xml -nb-configuration.xml -.nb-gradle/ - -################################################################################ -# -# Windows OS -# -################################################################################ - -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - -################################################################################ -# -# Notepad++ -# -################################################################################ - -*.bak - -################################################################################ -# -# Vagrant -# -################################################################################ - -.vagrant/ - -################################################################################ -# -# TortoiseGit -# -################################################################################ - -# Project-level settings -/.tgitconfig - -################################################################################ -# -# NodeJS -# -################################################################################ - -# Logs -logs -*.log - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git -node_modules - -################################################################################ -# -# Composer -# -################################################################################ - -composer.phar -vendor/ - -# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file composer.lock -.gitignore +/vendor/ +/.idea/ +/build/ +.phpunit.result.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index 47c56b6..291f342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,21 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.0.0] - 2021-09-14 + +### Changed + +- The minimal required PHP version is bumped to PHP 7.4. +- Changed the namespace to `Vdhicts\Replacer`. + ## [2.0.0] - 2019-12-11 ### Added + - Add this changelog to this package. ### Changed + - Change `setOpenDelimiter` and `setCloseDelimiter` to be fluent. - Move the `data` parameter to the `process` method so multiple templates can be rendered with the same `Replacer` instance. @@ -18,4 +27,5 @@ instance. ## [1.0.0] - 2018-02-19 ### Added + - Initial release diff --git a/README.md b/README.md index a9104bb..e1b2661 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This package allows you to easily replace values in text for templating purposes ## Requirements -This package requires PHP 7.0+. +This package requires PHP 7.4+. ## Installation @@ -61,8 +61,8 @@ per feature. In exchange you will be credited as contributor on this page. ## Security -If you discover any security related issues in this or other packages of Vdhicts, please email info@vdhicts.nl instead -of using the issue tracker. +If you discover any security related issues in this or other packages of Vdhicts, please email security@vdhicts.nl +instead of using the issue tracker. ## License @@ -70,6 +70,5 @@ This package is open-sourced software licensed under the [MIT license](http://op ## About vdhicts -[Van der Heiden ICT services](https://www.vdhicts.nl) is the name of my personal company for which I work as -freelancer. Van der Heiden ICT services develops and implements IT solutions for businesses and educational -institutions. +[Vdhicts](https://www.vdhicts.nl) is the name of my personal company. Vdhicts develops and implements IT solutions for +businesses and educational institutions. diff --git a/composer.json b/composer.json index 9c90ddd..772c904 100644 --- a/composer.json +++ b/composer.json @@ -12,14 +12,24 @@ ], "autoload": { "psr-4": { - "Vdhicts\\Dicms\\Replacer\\": "src/" + "Vdhicts\\Replacer\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Vdhicts\\Replacer\\Test\\": "tests/" } }, "require": { - "php" : "~7.0" + "php" : "^7.4|^8.0" }, "require-dev": { - "phpunit/phpunit": "^6.1" + "phpunit/phpunit": "^9.0", + "vimeo/psalm": "^4.10" + }, + "scripts": { + "test": "vendor/bin/phpunit", + "analyse": "vendor/bin/psalm" }, "config": { "sort-packages": true diff --git a/phpunit.xml b/phpunit.xml index a160a62..cb06a93 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,25 +1,29 @@ - - + + + + + src/ + + + + + tests/unit - - - src/ - - - - - + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..8dc065a --- /dev/null +++ b/psalm.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/src/Replacer.php b/src/Replacer.php index e164da9..2a35ff0 100644 --- a/src/Replacer.php +++ b/src/Replacer.php @@ -1,6 +1,6 @@ setOpenDelimiter($openDelimiter); - $this->setCloseDelimiter($closeDelimiter); - } - - /** - * Holds the open delimiter for the tokens. - * @return string - */ - private function getOpenDelimiter(): string - { - return $this->openDelimiter; + $this->openDelimiter = $openDelimiter; + $this->closeDelimiter = $closeDelimiter; } - /** - * Stores the open delimiter for the tokens. - * @param string $openDelimiter - * @return Replacer - */ public function setOpenDelimiter(string $openDelimiter = '['): self { $this->openDelimiter = $openDelimiter; - return $this; } - /** - * Returns the close delimiter for the tokens. - * @return string - */ - private function getCloseDelimiter(): string - { - return $this->closeDelimiter; - } - - /** - * Stores the close delimiter for the tokens. - * @param string $closeDelimiter - * @return Replacer - */ public function setCloseDelimiter(string $closeDelimiter = ']'): self { $this->closeDelimiter = $closeDelimiter; - return $this; } - /** - * Formats the token and adds the delimiters. - * @param string $token - * @return string - */ private function formatToken(string $token): string { return sprintf( '%s%s%s', - $this->getOpenDelimiter(), + $this->openDelimiter, strtoupper($token), - $this->getCloseDelimiter() + $this->closeDelimiter ); } - /** - * Returns the tokens. - * @param array $data - * @return array - */ private function getTokens(array $data = []): array { return array_map( @@ -99,16 +54,6 @@ function ($token) { ); } - /** - * Returns the values of the tokens. - * @param array $data - * @return array - */ - private function getTokenValues(array $data = []): array - { - return array_values($data); - } - /** * Replaces the token with its values in the provided text. * @param string $text @@ -124,7 +69,7 @@ public function process(string $text = '', array $data = []): string } // Determine the values with which the tokens should be replaced - $replaceValues = $this->getTokenValues($data); + $replaceValues = array_values($data); // Replace the tokens with the values return str_replace($replaceTokens, $replaceValues, $text); diff --git a/tests/unit/ReplacerTest.php b/tests/unit/ReplacerTest.php index 4f69a89..e307f79 100644 --- a/tests/unit/ReplacerTest.php +++ b/tests/unit/ReplacerTest.php @@ -1,9 +1,9 @@