diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2b209ef..fd6304c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,5 +1,5 @@ { - "name": "like/composer-empty", + "name": "eloquent-ide-helper", "dockerComposeFile": [ "../docker-compose.yml" ], diff --git a/.docker/sql/database.sql b/.docker/sql/database.sql new file mode 100644 index 0000000..80e07a1 --- /dev/null +++ b/.docker/sql/database.sql @@ -0,0 +1,25 @@ +CREATE TABLE `products` ( + `id` int(6) NOT NULL, + `subcategory_id` int(6) NOT NULL, + `name` varchar(100) NOT NULL, + `reference` int(10) NULL DEFAULT NULL, + `price` decimal(10,2) NOT NULL DEFAULT 0.00 +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +CREATE TABLE `subcategories` ( + `id` int(6) NOT NULL, + `name` varchar(40) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +ALTER TABLE `products` + ADD PRIMARY KEY (`id`); + +ALTER TABLE `subcategories` + ADD PRIMARY KEY (`id`); + +ALTER TABLE `products` + MODIFY `id` int(6) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `subcategories` + MODIFY `id` int(6) NOT NULL AUTO_INCREMENT; +COMMIT; \ No newline at end of file diff --git a/.env.example b/.env.example index 1d69973..8455390 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ GITHUB_TOKEN= -CODECOMMIT_USER= -CODECOMMIT_PASSWORD= -PHP_VERSION=56|73|74|80 \ No newline at end of file +PHP_VERSION=56|73|74|80 +PMA_PORT= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2230949..11035a6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ composer.lock tests/phpunit.*.xml .phpunit.result.cache .php_cs.cache -.php-cs-fixer.cache \ No newline at end of file +.php-cs-fixer.cache +.docker/data/ \ No newline at end of file diff --git a/composer.json b/composer.json index d647d3c..341352d 100644 --- a/composer.json +++ b/composer.json @@ -1,26 +1,29 @@ { - "name": "likesistemas/nomedalib", + "name": "likesistemas/eloquent-ide-helper", "type": "library", - "description": "Descriçãoo da biblioteca.", - "repositories": [ - {"type": "composer", "url": "https://composer.likesistemas.com.br/"} - ], + "description": "Using `barryvdh/laravel-ide-helper` without laravel framework.", "require": { - "php": ">=5.6" + "php": ">=5.6", + "barryvdh/laravel-ide-helper": "^2.4", + "illuminate/filesystem": "^5.4", + "illuminate/container": "^5.4", + "doctrine/dbal": "^2.5" }, "require-dev": { - "phpunit/phpunit": "^5.0 || ^9.0" + "phpunit/phpunit": "^5.0 || ^9.0", + "likesistemas/eloquent-external": "^1.1" }, "autoload": { "psr-4": { - "Like\\NomeDaLib\\": "src/" + "Like\\Eloquent\\IdeHelper\\": "src/" } }, "autoload-dev": { "psr-4": { - "Like\\NomeDaLib\\Tests\\": "tests/" + "Like\\Eloquent\\IdeHelper\\Tests\\": "tests/" } }, + "bin": ["bin/ide-helper"], "authors": [ { "name": "Like Sistemas", @@ -33,5 +36,10 @@ "fix:ci": "php-cs-fixer fix --dry-run --stop-on-violation", "test": "phpunit", "analyse": "phpstan analyse" + }, + "config": { + "allow-plugins": { + "kylekatarnls/update-helper": true + } } } diff --git a/docker-compose.phpmyadmin.yml b/docker-compose.phpmyadmin.yml new file mode 100644 index 0000000..3abff23 --- /dev/null +++ b/docker-compose.phpmyadmin.yml @@ -0,0 +1,18 @@ +version: '3.7' + +networks: + github: + name: github + driver: bridge + +services: + + phpmyadmin: + image: phpmyadmin/phpmyadmin:latest + environment: + - PMA_HOSTS=mysql + - UPLOAD_LIMIT=300M + ports: + - ${PMA_PORT:-9000}:80 + networks: + - github \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index d4e9842..57d5680 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,25 @@ services: - CODECOMMIT_USER=$CODECOMMIT_USER - CODECOMMIT_PASSWORD=$CODECOMMIT_PASSWORD - URL_SENTRY=${URL_SENTRY} + - DB_HOST=mysql volumes: - ./:/var/www/public/ + networks: + - github + links: + - mysql + depends_on: + - mysql + + mysql: + image: ${DB_ENGINE:-mariadb}:${DB_VERSION:-10.4.12} + command: --innodb-use-native-aio=0 --character-set-server=latin1 --collation-server=latin1_swedish_ci + volumes: + - ./.docker/data/${DB_ENGINE:-mariadb}-${DB_VERSION:-10.4.12}/:/var/lib/mysql + - ./.docker/sql/:/docker-entrypoint-initdb.d/ + environment: + - MYSQL_DATABASE=${MYSQL_DATABASE:-eloquent} + - MYSQL_ROOT_PASSWORD=root + - TZ=America/Fortaleza networks: - github \ No newline at end of file diff --git a/src/Application.php b/src/Application.php new file mode 100644 index 0000000..119dd10 --- /dev/null +++ b/src/Application.php @@ -0,0 +1,13 @@ +add(new GenerateDocsModelsCommand()); + } +} diff --git a/src/Commands/AbstractCommand.php b/src/Commands/AbstractCommand.php new file mode 100644 index 0000000..2df8beb --- /dev/null +++ b/src/Commands/AbstractCommand.php @@ -0,0 +1,49 @@ +style = new SymfonyStyle($input, $output); + + if (! Container::getInstance()->bound('config')) { + $this->loadConfig(); + } + } + + private function loadConfig() { + $cwd = getcwd() . DIRECTORY_SEPARATOR; + $filename = 'ide-helper.php'; + $src = $cwd . $filename; + + if (! file_exists($src)) { + throw new LogicException("Config file not found. Filename: {$src}."); + } + + $config = include($src); + + if (! $config instanceof Config) { + throw new LogicException("Config not is \Like\Eloquent\IdeHelper\Config."); + } + + Container::getInstance()->instance('config', $config); + + $this->style->title('Reading configurations...'); + $this->style->text('Using base path: ' . base_path()); + $this->style->text('Using models folders: ' . join(', ', $config['ide-helper.model_locations'])); + } +} diff --git a/src/Commands/GenerateDocsModelsCommand.php b/src/Commands/GenerateDocsModelsCommand.php new file mode 100644 index 0000000..0596c83 --- /dev/null +++ b/src/Commands/GenerateDocsModelsCommand.php @@ -0,0 +1,33 @@ +setAliases(['models']); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $this->style->title('Writing documentation to models'); + + $fileSystem = new Filesystem(); + $command = new ModelsCommand($fileSystem); + $command->setLaravel(Container::getInstance()); + return $command->run( + new ArrayInput(['--write' => true, '--reset' => true]), + new ConsoleOutput() + ); + } +} diff --git a/src/Config.php b/src/Config.php new file mode 100644 index 0000000..5587215 --- /dev/null +++ b/src/Config.php @@ -0,0 +1,39 @@ +config = $config; + } + + public function get($key, $defaultVaue = null) { + return Arr::get($this->config, $key, $defaultVaue); + } + + public function offsetExists($offset) { + throw new RuntimeException('Not implemented because we didn\'t need it yet'); + } + + public function offsetGet($offset) { + return $this->get($offset); + } + + public function offsetSet($offset, $value) { + throw new RuntimeException('Not implemented because we didn\'t need it yet'); + } + + public function offsetUnset($offset) { + throw new RuntimeException('Not implemented because we didn\'t need it yet'); + } +} diff --git a/src/NomeDaLib.php b/src/NomeDaLib.php deleted file mode 100644 index 996e4a1..0000000 --- a/src/NomeDaLib.php +++ /dev/null @@ -1,6 +0,0 @@ -run(); diff --git a/src/laravel-functions.php b/src/laravel-functions.php new file mode 100644 index 0000000..ed899d8 --- /dev/null +++ b/src/laravel-functions.php @@ -0,0 +1,11 @@ +resolved('base-path') ?: getcwd(); +} + +function config() { + return Container::getInstance()->resolved('config'); +} diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php new file mode 100644 index 0000000..289dd7a --- /dev/null +++ b/tests/ApplicationTest.php @@ -0,0 +1,12 @@ +assertInstanceOf(Application::class, new Application()); + } +} diff --git a/tests/Config.php b/tests/Config.php new file mode 100644 index 0000000..5298be5 --- /dev/null +++ b/tests/Config.php @@ -0,0 +1,47 @@ +define(Subcategory::class, function (Faker $faker) { + return [ + 'name' => $faker->name, + ]; +}); + +$factory->define(Product::class, function (Faker $faker) { + return [ + 'name' => $faker->name, + 'price' => 10, + 'reference' => DatabaseFaker::unique($faker, 'referenciaProduto')->numberBetween(1, 100), + ]; +}); diff --git a/tests/Models/Product.php b/tests/Models/Product.php new file mode 100644 index 0000000..2108954 --- /dev/null +++ b/tests/Models/Product.php @@ -0,0 +1,29 @@ +belongsTo(Subcategory::class); + } +} diff --git a/tests/Models/Subcategory.php b/tests/Models/Subcategory.php new file mode 100644 index 0000000..e52aacc --- /dev/null +++ b/tests/Models/Subcategory.php @@ -0,0 +1,18 @@ +assertInstanceOf(NomeDaLib::class, new NomeDaLib()); - } -} diff --git a/tests/ide-helper.php b/tests/ide-helper.php new file mode 100644 index 0000000..5145a3b --- /dev/null +++ b/tests/ide-helper.php @@ -0,0 +1,19 @@ +instance( + DatabaseConfig::class, + new TestsConfig() +); +Eloquent::init(); + +return new Config([ + 'ide-helper.model_locations' => [ + 'Models/', + ], +]);