├── .github └── workflows │ ├── dependabot-auto-merge.yml │ ├── fix-styling.yml │ ├── tests.yml │ └── update-changelog.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src ├── Generator.php └── Words │ ├── Adjective.php │ └── Noun.php └── tests └── GeneratorTest.php /.github/workflows/dependabot-auto-merge.yml: -------------------------------------------------------------------------------- 1 | name: dependabot-auto-merge 2 | 3 | on: pull_request_target 4 | 5 | permissions: 6 | pull-requests: write 7 | contents: write 8 | 9 | jobs: 10 | dependabot: 11 | runs-on: ubuntu-latest 12 | if: ${{ github.actor == 'dependabot[bot]' }} 13 | steps: 14 | - name: Dependabot metadata 15 | id: metadata 16 | uses: dependabot/fetch-metadata@v1.3.5 17 | with: 18 | github-token: "${{ secrets.GITHUB_TOKEN }}" 19 | 20 | - name: Auto-merge Dependabot PRs for semver-minor updates 21 | if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} 22 | run: gh pr merge --auto --merge "$PR_URL" 23 | env: 24 | PR_URL: ${{github.event.pull_request.html_url}} 25 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 26 | 27 | - name: Auto-merge Dependabot PRs for semver-patch updates 28 | if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} 29 | run: gh pr merge --auto --merge "$PR_URL" 30 | env: 31 | PR_URL: ${{github.event.pull_request.html_url}} 32 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 33 | -------------------------------------------------------------------------------- /.github/workflows/fix-styling.yml: -------------------------------------------------------------------------------- 1 | name: Check & fix styling 2 | 3 | on: push 4 | 5 | jobs: 6 | fix-styling: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - name: Checkout code 11 | uses: actions/checkout@v3 12 | 13 | - name: Setup PHP 14 | uses: shivammathur/setup-php@v2 15 | with: 16 | php-version: '8.2' 17 | tools: pint 18 | 19 | - name: Run Laravel Pint 20 | run: pint --preset laravel 21 | 22 | - name: Commit changes 23 | uses: stefanzweifel/git-auto-commit-action@v4 24 | with: 25 | commit_message: Fix styling 26 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: tests 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | - cron: '0 0 * * *' 8 | 9 | jobs: 10 | tests: 11 | runs-on: ubuntu-20.04 12 | strategy: 13 | fail-fast: true 14 | matrix: 15 | php: [ 7.3, 7.4, '8.0', 8.1, 8.2, 8.3 ] 16 | 17 | name: PHP ${{ matrix.php }} 18 | steps: 19 | - name: Checkout code 20 | uses: actions/checkout@v2 21 | 22 | - name: Setup PHP 23 | uses: shivammathur/setup-php@v2 24 | with: 25 | php-version: ${{ matrix.php }} 26 | ini-values: error_reporting=E_ALL 27 | tools: composer:v2 28 | coverage: none 29 | 30 | - name: Install dependencies 31 | uses: nick-invision/retry@v1 32 | with: 33 | timeout_minutes: 5 34 | max_attempts: 5 35 | command: composer update --${{ matrix.stability }} 36 | 37 | - name: Execute tests 38 | run: vendor/bin/phpunit --verbose 39 | -------------------------------------------------------------------------------- /.github/workflows/update-changelog.yml: -------------------------------------------------------------------------------- 1 | name: Update Changelog on PR Merge 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - closed 7 | 8 | jobs: 9 | update-changelog: 10 | name: Update Changelog 11 | runs-on: ubuntu-latest 12 | if: github.event.pull_request.merged == true 13 | 14 | permissions: 15 | contents: write 16 | 17 | steps: 18 | - name: Checkout code 19 | uses: actions/checkout@v3 20 | with: 21 | ref: ${{ github.event.pull_request.base.ref }} 22 | fetch-depth: 0 23 | 24 | - name: Determine changelog section to update 25 | id: sections 26 | run: | 27 | section="" 28 | labels=$(echo '${{ toJSON(github.event.pull_request.labels.*.name) }}' | jq -r '.[]') 29 | for label in $labels; do 30 | lower_label=$(echo "$label" | tr '[:upper:]' '[:lower:]') 31 | case "$lower_label" in 32 | enhancement|feature) section="Added"; break;; 33 | bug|bugfix|fix|patch) section="Fixed"; break;; 34 | change) section="Changed"; break;; 35 | optimization|improvement|performance|refactor) section="Optimized"; break;; 36 | deprecation|deprecated) section="Deprecated"; break;; 37 | revert) section="Reverted"; break;; 38 | removal) section="Removed"; break;; 39 | security) section="Security"; break;; 40 | esac 41 | done 42 | 43 | if [ -z "$section" ]; then 44 | echo "No matching label found for changelog entry, skipping changelog update." 45 | exit 0 46 | else 47 | echo "section=$section" >> $GITHUB_OUTPUT 48 | fi 49 | 50 | - name: Add entry to CHANGELOG.md 51 | if: steps.sections.outputs.section != '' 52 | uses: claudiodekker/changelog-updater@master 53 | with: 54 | section: "${{ steps.sections.outputs.section }}" 55 | entry-text: "${{ github.event.pull_request.title }}" 56 | entry-link: "${{ github.event.pull_request.html_url }}" 57 | 58 | - name: Commit updated CHANGELOG 59 | if: steps.sections.outputs.section != '' 60 | uses: stefanzweifel/git-auto-commit-action@v4 61 | with: 62 | branch: ${{ github.event.pull_request.base.ref }} 63 | commit_message: "Update CHANGELOG.md w/ PR #${{ github.event.pull_request.number }}" 64 | file_pattern: CHANGELOG.md 65 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /.vscode 3 | /vendor 4 | .phpunit.result.cache 5 | composer.lock 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [v1.5.0](https://github.com/claudiodekker/word-generator/compare/v1.4.0...v1.5.0) - 2024-01-31 9 | 10 | ### Added 11 | 12 | - Add PHP 8.3 Support ([#12](https://github.com/claudiodekker/word-generator/pull/12)) 13 | 14 | 15 | ## [v1.4.0](https://github.com/claudiodekker/word-generator/compare/v1.3.0...v1.4.0) - 2023-10-12 16 | 17 | ### Added 18 | 19 | - Add option for controlling the total word length ([#8](https://github.com/claudiodekker/word-generator/pull/8)) 20 | 21 | ### Optimized 22 | 23 | - Add more adjectives and nouns to the built-in lists ([#9](https://github.com/claudiodekker/word-generator/pull/9)) 24 | 25 | 26 | ## [v1.3.0](https://github.com/claudiodekker/word-generator/compare/v1.2.0...v1.3.0) - 2023-07-21 27 | 28 | ### Added 29 | 30 | - Add ability to reset custom word lists ([#5](https://github.com/claudiodekker/word-generator/pull/5)) 31 | 32 | 33 | ## [v1.2.0](https://github.com/claudiodekker/word-generator/compare/v1.1.0...v1.2.0) - 2022-12-20 34 | 35 | ### Added 36 | 37 | - PHP 8.2 support ([#3](https://github.com/claudiodekker/word-generator/pull/3)) 38 | 39 | ### Fixed 40 | 41 | - Fixed the README.md status badges, and auto-fixed code style through new Github Action flows ([#4](https://github.com/claudiodekker/word-generator/pull/4)) 42 | 43 | 44 | ## [v1.1.0](https://github.com/claudiodekker/word-generator/compare/v1.0.1...v1.1.0) - 2022-03-23 45 | 46 | ### Added 47 | 48 | - Ability to set custom adjectives and/or nouns ([#2](https://github.com/claudiodekker/word-generator/pull/2)) 49 | 50 | 51 | ## [v1.0.1](https://github.com/claudiodekker/word-generator/compare/v1.0.0...v1.0.1) - 2022-03-22 52 | 53 | ### Fixed 54 | 55 | - The list of nouns included duplicates, and wasn't sorted alphabetically. ([#1](https://github.com/claudiodekker/word-generator/pull/1)) 56 | 57 | 58 | ## v1.0.0 - 2022-03-22 59 | 60 | ### Added 61 | 62 | - Initial release 63 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Claudio Dekker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/claudiodekker/word-generator.svg)](https://packagist.org/packages/claudiodekker/word-generator) 2 | [![Github Tests Action Status](https://github.com/claudiodekker/word-generator/actions/workflows/tests.yml/badge.svg)](https://github.com/claudiodekker/word-generator/actions/workflows/tests.yml) 3 | [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/claudiodekker/word-generator/fix-styling.yml?label=code%20style&logo=github&branch=master)](https://github.com/claudiodekker/word-generator/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amaster) 4 | [![Total Downloads](https://img.shields.io/packagist/dt/claudiodekker/word-generator.svg)](https://packagist.org/packages/claudiodekker/word-generator) 5 | 6 | # Word Generator 7 | 8 | Generates creative words by randomly combining adjectives and nouns. 9 | This is useful for situations in which you need to generate a name that is unique or memorable. 10 | 11 | ## Installation 12 | 13 | To install the package, run the following command: 14 | ```bash 15 | composer require claudiodekker/word-generator 16 | ``` 17 | 18 | ## Usage 19 | 20 | ```php 21 | 2 | 14 | 15 | 16 | ./tests 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Generator.php: -------------------------------------------------------------------------------- 1 | assertCount(2, $partsA); 19 | $this->assertNotNull($partsA[0]); 20 | $this->assertNotNull($partsA[1]); 21 | 22 | $partsB = explode('%', $wordB); 23 | $this->assertCount(2, $partsB); 24 | $this->assertNotNull($partsB[0]); 25 | $this->assertNotNull($partsB[1]); 26 | 27 | $this->assertCount(1, explode('%', $wordA)); 28 | $this->assertCount(1, explode('-', $wordB)); 29 | } 30 | 31 | /** @test */ 32 | public function it_separates_using_a_space_by_default(): void 33 | { 34 | $word = Generator::generate(); 35 | 36 | $parts = explode(' ', $word); 37 | $this->assertCount(2, $parts); 38 | $this->assertNotNull($parts[0]); 39 | $this->assertNotNull($parts[1]); 40 | } 41 | 42 | /** @test */ 43 | public function it_generates_a_different_combination_each_time(): void 44 | { 45 | $wordA = Generator::generate(); 46 | $wordB = Generator::generate(); 47 | 48 | $this->assertNotSame($wordA, $wordB); 49 | } 50 | 51 | /** @test */ 52 | public function it_can_use_custom_word_lists(): void 53 | { 54 | Generator::setWordLists(['foo'], ['bar']); 55 | 56 | $this->assertSame('foo bar', Generator::generate()); 57 | } 58 | 59 | /** @test */ 60 | public function it_can_reset_the_custom_word_lists(): void 61 | { 62 | Generator::setWordLists(['foo'], ['bar']); 63 | 64 | Generator::reset(); 65 | 66 | $this->assertNotSame('foo bar', Generator::generate()); 67 | } 68 | 69 | /** @test */ 70 | public function it_can_generate_words_of_varying_length(): void 71 | { 72 | $this->assertCount(2, \explode(' ', Generator::generate(' '))); 73 | $this->assertCount(3, \explode(' ', Generator::generate(' ', 3))); 74 | $this->assertCount(4, \explode(' ', Generator::generate(' ', 4))); 75 | $this->assertCount(5, \explode(' ', Generator::generate(' ', 5))); 76 | $this->assertCount(6, \explode(' ', Generator::generate(' ', 6))); 77 | } 78 | 79 | /** @test */ 80 | public function it_throws_an_error_on_invalid_length(): void 81 | { 82 | $this->expectException(LengthException::class); 83 | 84 | Generator::generate(' ', 1); 85 | } 86 | } 87 | --------------------------------------------------------------------------------