diff --git a/.gitignore b/.gitignore index 585bc12..4cbc6e2 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ psalm.xml vendor .php-cs-fixer.cache index.php +generate.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c93e5c..4a27014 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,21 @@ All notable changes to `business-name-generator` will be documented in this file. +## v1.2.1 - 2024-06-08 + +**Full Changelog**: https://github.com/designbycode/business-name-generator/compare/v1.2.0...v1.2.1 + +- Update test and name + +## v1.2.0 - 2024-06-08 + +**Full Changelog**: https://github.com/designbycode/business-name-generator/compare/v1.1.0...v1.2.0 + +- Added method for creating multiple names at once + +## v1.1.0 - 2024-06-08 + +**Full Changelog**: https://github.com/designbycode/business-name-generator/commits/v1.1.0 + +- Splite code into seperate classes +- Added test diff --git a/README.md b/README.md index 6f11d66..b2849d6 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,10 @@ -# This is my package business-name-generator +# Business Name Generator [![Latest Version on Packagist](https://img.shields.io/packagist/v/designbycode/business-name-generator.svg?style=flat-square)](https://packagist.org/packages/designbycode/business-name-generator) [![Tests](https://img.shields.io/github/actions/workflow/status/designbycode/business-name-generator/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/designbycode/business-name-generator/actions/workflows/run-tests.yml) [![Total Downloads](https://img.shields.io/packagist/dt/designbycode/business-name-generator.svg?style=flat-square)](https://packagist.org/packages/designbycode/business-name-generator) -This is where your description should go. Try and limit it to a paragraph or two. Consider adding a small example. - - -We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). +The BusinessNameGenerator package is designed to help you generate creative and unique business names by combining adjectives and nouns from various categories. The package provides default, funny, playful, and color-related lists for both adjectives and nouns, giving you plenty of options to create a memorable business name. ## Installation @@ -18,12 +15,111 @@ composer require designbycode/business-name-generator ``` ## Usage +### Basic Usage ```php -$skeleton = new Designbycode\BusinessNameGenerator(); -echo $skeleton->echoPhrase('Hello, Designbycode!'); +require 'vendor/autoload.php'; + +use Designbycode\BusinessNameGenerator\BusinessNameGenerator; +use Designbycode\BusinessNameGenerator\Nouns; +use Designbycode\BusinessNameGenerator\Adjectives; + +// Create a new BusinessNameGenerator instance +$generator = new BusinessNameGenerator(); + +// Generate a business name using default adjectives and funny nouns +$businessName = $generator->generate('default', 'funny'); +echo $businessName; // Example output: "Innovative Banana" ``` +### Custom Adjectives and Nouns +You can also provide your own lists of adjectives and nouns: + +```php +$customAdjectives = ["Cool", "Amazing", "Super"]; +$customNouns = ["Shop", "Hub", "Center"]; + +$generator = new BusinessNameGenerator($customAdjectives, $customNouns); + +$businessName = $generator->generate(); +echo $businessName; // Example output: "Super Shop" + +``` +### Using Specific Categories +You can generate business names based on specific categories of adjectives and nouns: + +```php +$generator = new BusinessNameGenerator(); + +// Generate a business name using playful adjectives and color-related nouns +$businessName = $generator->generate('playful', 'color'); +echo $businessName; // Example output: "Cheerful Blue" +``` + +## Adjective and Noun Categories +### Adjective Categories +- default: Standard business-related adjectives. +- funny: Whimsical and humorous adjectives. +- playful: Light-hearted and playful adjectives. +- color: Color-related adjectives. +- all: A combination of all the above categories. + +### Noun Categories +- default: Standard business-related nouns. +- funny: Whimsical and humorous nouns. +- playful: Light-hearted and playful nouns. +- color: Color-related nouns. +- all: A combination of all the above categories. + +### Extending the Lists +If you want to extend the list of adjectives or nouns, you can create your own classes that implement the HasGeneratorLists interface. + +```php +namespace YourNamespace; + +use Designbycode\BusinessNameGenerator\HasGeneratorLists; + +class CustomAdjectives implements HasGeneratorLists +{ + public function default(): array + { + return ["Energetic", "Bold", "Brilliant"]; + } + + public function funny(): array + { + return ["Zany", "Wacky", "Goofy"]; + } + + public function playful(): array + { + return ["Bouncy", "Jovial", "Perky"]; + } + + public function color(): array + { + return ["Crimson", "Amber", "Sapphire"]; + } +} + +``` + +Then use your custom class with the BusinessNameGenerator: + +```php + +use Designbycode\BusinessNameGenerator\BusinessNameGenerator; +use YourNamespace\CustomAdjectives; +use Designbycode\BusinessNameGenerator\Nouns; + +$generator = new BusinessNameGenerator((new CustomAdjectives())->default(), (new Nouns())->default()); + +$businessName = $generator->generate('default', 'default'); +echo $businessName; // Example output: "Energetic Solutions" + + +```` + ## Testing ```bash diff --git a/composer.json b/composer.json index 2c55aba..c3e22e7 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "^8.1" + "php": "^8.1|^8.2|^8.3" }, "require-dev": { "pestphp/pest": "^2.20", @@ -34,7 +34,7 @@ }, "scripts": { "test": "vendor/bin/pest", - "test-coverage": "vendor/bin/pest --coverage", + "test-coverage": "vendor/bin/pest --coverage", "format": "vendor/bin/pint" }, "config": { diff --git a/src/Adjectives.php b/src/Adjectives.php new file mode 100644 index 0000000..640baba --- /dev/null +++ b/src/Adjectives.php @@ -0,0 +1,100 @@ +default(), + $this->funny(), + $this->playful(), + $this->color() + ); + } +} diff --git a/src/BusinessNameGenerator.php b/src/BusinessNameGenerator.php index 25039cf..2b6e9b9 100644 --- a/src/BusinessNameGenerator.php +++ b/src/BusinessNameGenerator.php @@ -4,109 +4,74 @@ class BusinessNameGenerator { - private array $adjectives; - private array $nouns; + public function __construct(public array $adjectives = [], public array $nouns = []) + { + $this->adjectives = $adjectives ?: (new Adjectives())->default(); + $this->nouns = $nouns ?: (new Nouns())->default(); + } + + public function setAdjectives(array $adjectivesList): void + { + $this->adjectives = $adjectivesList; + } - public function __construct() + public function setNouns(array $nounsList): void { - $this->adjectives = [ - 'Innovative', 'Creative', 'Dynamic', 'Strategic', 'Global', - 'Agile', 'Efficient', 'Robust', 'Scalable', 'Intuitive', - 'Advanced', 'Leading', 'Reliable', 'Custom', 'Smart', - 'Visionary', 'Pioneering', 'Cutting-edge', 'Groundbreaking', 'Revolutionary', - 'Trailblazing', 'Futuristic', 'Ingenious', 'Resourceful', 'Versatile', - 'Proactive', 'Progressive', 'Synergistic', 'Transformative', 'Impactful', - 'Elegant', 'Sophisticated', 'Sleek', 'Streamlined', 'User-friendly', - 'High-performance', 'Next-gen', 'State-of-the-art', 'Premier', 'Premium', - 'Elite', 'Exclusive', 'Exceptional', 'Top-tier', 'Outstanding', - 'Remarkable', 'Impressive', 'Phenomenal', 'Astounding', 'Extraordinary', - 'Superior', 'Unparalleled', 'Unmatched', 'Distinctive', 'Unique', - 'Original', 'Inventive', 'Nimble', 'Flexible', 'Adaptable', - 'Energetic', 'Enthusiastic', 'Passionate', 'Driven', 'Ambitious', - 'Motivated', 'Committed', 'Dedicated', 'Focused', 'Persistent', - 'Tenacious', 'Resilient', 'Sturdy', 'Strong', 'Powerful', - 'Mighty', 'Formidable', 'Tough', 'Dependable', 'Consistent', - 'Steady', 'Trustworthy', 'Honest', 'Ethical', 'Principled', - 'Fair', 'Just', 'Responsible', 'Accountable', 'Transparent', - 'Open', 'Direct', 'Straightforward', 'Clear', 'Plain', - 'Simple', 'Uncomplicated', 'Productive', 'Proficient', 'Skilled', - 'Competent', 'Capable', 'Experienced', 'Knowledgeable', 'Expert', - 'Masterful', 'Accomplished', 'Talented', 'Gifted', 'Amazing', - 'Incredible', 'Fantastic', 'Fabulous', 'Wonderful', 'Marvelous', - 'Magnificent', 'Brilliant', 'Radiant', 'Luminous', 'Dazzling', - 'Glowing', 'Shining', 'Sparkling', 'Gleaming', 'Bright', - 'Vivid', 'Vibrant', 'Colorful', - ]; - $this->nouns = [ - 'Solutions', 'Trading', 'Technologies', 'Enterprises', 'Consulting', 'Systems', - 'Networks', 'Services', 'Partners', 'Innovations', 'Ventures', - 'Concepts', 'Dynamics', 'Strategies', 'Advisors', 'Associates', - 'Labs', 'Works', 'Platforms', 'Designs', 'Developments', - 'Resources', 'Holdings', 'Group', 'Agency', 'Creations', - 'Studios', 'Marketing', 'Investments', 'Analytics', 'Intelligence', - 'Management', 'Research', 'Productions', 'Events', 'Projects', - 'Industries', 'Entities', 'Firms', 'Corporation', 'Companies', - 'Businesses', 'Organizations', 'Sectors', 'Institutions', 'Establishments', - 'Operations', 'Facilities', 'Providers', 'Vendors', 'Suppliers', - 'Manufacturers', 'Distributors', 'Retailers', 'Wholesalers', 'Contractors', - 'Builders', 'Developers', 'Consultants', 'Advisers', 'Traders', - 'Brokers', 'Dealers', 'Agencies', 'Agents', 'Representatives', - 'Planners', 'Designers', 'Architects', 'Engineers', 'Technicians', - 'Specialists', 'Experts', 'Professionals', 'Practitioners', 'Clinics', - 'Centers', 'Institutes', 'Programs', 'Academies', 'Schools', - 'Colleges', 'Universities', 'Libraries', 'Museums', 'Laboratories', - 'Workshops', 'Studios', 'Offices', 'Headquarters', 'Branches', - 'Divisions', 'Departments', 'Units', 'Sections', 'Groups', - 'Teams', 'Forums', 'Associations', 'Unions', 'Syndicates', - 'Alliances', 'Coalitions', 'Partnerships', 'Federations', 'Networks', - 'Clusters', 'Consortiums', 'Conglomerates', 'Bodies', 'Outfits', - 'Outposts', 'Premises', 'Locations', 'Sites', 'Complexes', - 'Campuses', 'Bases', 'Centers', 'Hubs', 'Zones', - 'Regions', 'Territories', 'Districts', 'Areas', 'Quadrants', - 'Divisions', 'Departments', 'Units', 'Groups', 'Teams', - 'Clans', 'Circles', 'Clubs', 'Societies', 'Guilds', - 'Fraternities', 'Sororities', 'Associations', 'Leagues', 'Unions', - 'Alliances', 'Coalitions', 'Partnerships', 'Fellowships', 'Confraternities', - 'Orders', 'Brotherhoods', 'Sisterhoods', 'Families', 'Dynasties', - 'Houses', 'Lineages', 'Tribes', 'Nations', 'Peoples', - 'Communities', 'Collectives', 'Bands', 'Gangs', 'Crews', - 'Posses', 'Squads', 'Units', 'Platoons', 'Companies', - 'Battalions', 'Regiments', 'Brigades', 'Corps', 'Armies', - 'Fleets', 'Navies', 'Flotillas', 'Squadrons', 'Wings', - 'Commands', 'Task Forces', 'Forces', 'Troops', 'Militias', - 'Guards', 'Reserves', 'Auxiliaries', 'Volunteers', 'Cadres', - 'Recruits', 'Conscripts', 'Draftees', 'Soldiers', 'Sailors', - 'Marines', 'Airmen', 'Aviators', 'Pilots', 'Crews', - 'Operators', 'Technicians', 'Mechanics', 'Engineers', 'Specialists', - 'Experts', 'Professionals', 'Practitioners', 'Consultants', 'Advisors', - 'Counselors', 'Guides', 'Mentors', 'Coaches', 'Trainers', - 'Instructors', 'Teachers', 'Educators', 'Tutors', 'Lecturers', - 'Professors', 'Researchers', 'Scholars', 'Scientists', 'Analysts', - 'Strategists', 'Planners', 'Designers', 'Architects', 'Builders', - 'Constructors', 'Developers', 'Producers', 'Creators', 'Makers', - 'Manufacturers', 'Fabricators', 'Assemblers', 'Contractors', 'Erectors', - 'Installers', 'Integrators', 'Implementers', 'Handlers', 'Manipulators', - 'Controllers', 'Regulators', 'Managers', 'Directors', 'Administrators', - 'Executives', 'Leaders', 'Chiefs', 'Heads', 'Principals', - 'Partners', 'Associates', 'Members', 'Stakeholders', 'Shareholders', - 'Investors', 'Backers', 'Supporters', 'Sponsors', 'Benefactors', - 'Patrons', 'Donors', 'Contributors', 'Funders', 'Financiers', - 'Bankers', 'Creditors', 'Lenders', 'Loaners', 'Bailors', - 'Insurers', 'Underwriters', 'Guarantors', 'Sureties', 'Vouchers', - 'Securities', 'Bondsmen', 'Trustees', 'Custodians', 'Guardians', - 'Caretakers', 'Wards', 'Beneficiaries', 'Inheritors', 'Heirs', - 'Successors', 'Assignees', 'Appointees', 'Nominees', 'Candidates', - 'Contestants', 'Challengers', 'Competitors', 'Rivals', 'Opponents', - 'Adversaries', 'Enemies', - ]; + $this->nouns = $nounsList; } - public function generate(): string + public function generate(string $adjectivesCategory = 'default', string $nounsCategory = 'default'): string { - $adjective = $this->adjectives[array_rand($this->adjectives)]; - $noun = $this->nouns[array_rand($this->nouns)]; + $adjectives = $this->adjectivesList($adjectivesCategory); + + $nouns = $this->nounsList($nounsCategory); + + $adjective = $adjectives[array_rand($adjectives)]; + $noun = $nouns[array_rand($nouns)]; return $adjective.' '.$noun; } + + public function generateMultiple(string $adjectivesCategory = 'default', string $nounsCategory = 'default', int $amount = 1): array + { + $adjectives = $this->adjectivesList($adjectivesCategory); + $nouns = $this->nounsList($nounsCategory); + + $names = []; + for ($i = 0; $i < $amount; $i++) { + $adjective = $adjectives[array_rand($adjectives)]; + $noun = $nouns[array_rand($nouns)]; + $names[] = $adjective.' '.$noun; + } + + return $names; + } + + + private function adjectivesList(string $adjectivesCategory): array + { + + return match (strtolower($adjectivesCategory)) { + 'funny' => (new Adjectives())->funny(), + 'playful' => (new Adjectives())->playful(), + 'color' => (new Adjectives())->color(), + 'all' => (new Adjectives())->all(), + default => $this->adjectives, + }; + + } + + private function nounsList(string $nounsCategory): array + { + + return match (strtolower($nounsCategory)) { + 'funny' => (new Nouns())->funny(), + 'playful' => (new Nouns())->playful(), + 'color' => (new Nouns())->color(), + 'all' => (new Nouns())->all(), + default => $this->nouns, + }; + + } } diff --git a/src/Colors.php b/src/Colors.php new file mode 100644 index 0000000..33a15a5 --- /dev/null +++ b/src/Colors.php @@ -0,0 +1,27 @@ +default(), + $this->funny(), + $this->playful(), + $this->color() + ); + } +} diff --git a/tests/BusinessNameGeneratorTest.php b/tests/BusinessNameGeneratorTest.php new file mode 100644 index 0000000..389eaac --- /dev/null +++ b/tests/BusinessNameGeneratorTest.php @@ -0,0 +1,107 @@ +adjectives = ['Funny', 'Playful', 'Colorful']; + $this->nouns = ['Cat', 'Dog', 'Elephant']; + $this->generator = new BusinessNameGenerator($this->adjectives, $this->nouns); +}); + +it('generates a business name using default lists', function () { + $generator = new BusinessNameGenerator(); + $businessName = $generator->generate(); + expect($businessName)->toBeString(); +}); + +it('generates a business name with custom adjectives and nouns', function () { + $customAdjectives = ['Cool', 'Amazing', 'Super']; + $customNouns = ['Shop', 'Hub', 'Center']; + $generator = new BusinessNameGenerator($customAdjectives, $customNouns); + + $businessName = $generator->generate(); + $parts = explode(' ', $businessName); + + expect($parts)->toHaveCount(2) + ->and($customAdjectives)->toContain($parts[0]) + ->and($customNouns)->toContain($parts[1]); +}); + +it('generates a business name using playful adjectives and color-related nouns', function () { + $generator = new BusinessNameGenerator(); + + $businessName = $generator->generate('playful', 'color'); + $parts = explode(' ', $businessName); + + $playfulAdjectives = (new Adjectives())->playful(); + $colorNouns = (new Nouns())->color(); + + expect($parts)->toHaveCount(2) + ->and($playfulAdjectives)->toContain($parts[0]) + ->and($colorNouns)->toContain($parts[1]); +}); + +it('generates a business name using funny adjectives and nouns', function () { + $generator = new BusinessNameGenerator(); + + $businessName = $generator->generate('funny', 'funny'); + $parts = explode(' ', $businessName); + + $funnyAdjectives = (new Adjectives())->funny(); + $funnyNouns = (new Nouns())->funny(); + + expect($parts)->toHaveCount(2) + ->and($funnyAdjectives)->toContain($parts[0]) + ->and($funnyNouns)->toContain($parts[1]); +}); + +it('sets custom adjectives and nouns after instantiation', function () { + $generator = new BusinessNameGenerator(); + + $customAdjectives = ['Bright', 'Shiny']; + $customNouns = ['Star', 'Galaxy']; + $generator->setAdjectives($customAdjectives); + $generator->setNouns($customNouns); + + $businessName = $generator->generate(); + $parts = explode(' ', $businessName); + + expect($parts)->toHaveCount(2) + ->and($customAdjectives)->toContain($parts[0]) + ->and($customNouns)->toContain($parts[1]); +}); + +test('it generates multiple business names', function () { + $amount = 10; + $names = $this->generator->generateMultiple('default', 'default', $amount); + + // Assert that the returned value is an array + expect($names)->toBeArray() + ->and($names)->toHaveCount($amount); + + // Assert that the array contains the correct number of names + + // Assert that each element in the array is a string + foreach ($names as $name) { + expect($name)->toBeString(); + } +}); + +test('it generates names using specified categories', function () { + // Assuming you have specific methods in Adjectives and Nouns classes for these categories + $amount = 5; + $names = $this->generator->generateMultiple('funny', 'color', $amount); + + // Assert that the returned value is an array + expect($names)->toBeArray() + ->and($names)->toHaveCount($amount); + + // Assert that the array contains the correct number of names + + // Assert that each element in the array is a string + foreach ($names as $name) { + expect($name)->toBeString(); + } +}); diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php deleted file mode 100644 index 5d36321..0000000 --- a/tests/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -toBeTrue(); -});