From 4d2843c3685e9f35fe61b784fd62a4b512707cd2 Mon Sep 17 00:00:00 2001 From: lotyp Date: Fri, 3 May 2024 19:27:08 +0300 Subject: [PATCH 1/2] feat: add remove method --- composer.json | 2 +- psalm-baseline.xml | 1 + psalm.xml | 1 - src/ActiveRecord.php | 14 +++++++++++ {config => src/Bridge/Yii3}/yii-bootstrap.php | 0 tests/src/ActiveRecordTest.php | 24 +++++++++++++++++++ 6 files changed, 40 insertions(+), 2 deletions(-) rename {config => src/Bridge/Yii3}/yii-bootstrap.php (100%) diff --git a/composer.json b/composer.json index 09c7745..971a765 100644 --- a/composer.json +++ b/composer.json @@ -99,7 +99,7 @@ "indent-style": "space" }, "config-plugin": { - "bootstrap": "config/yii-bootstrap.php" + "bootstrap": "src/Bridge/Yii3/yii-bootstrap.php" }, "laravel": { "providers": [ diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d34b240..44d7bad 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -6,6 +6,7 @@ + diff --git a/psalm.xml b/psalm.xml index 2cad805..760d5f9 100644 --- a/psalm.xml +++ b/psalm.xml @@ -16,7 +16,6 @@ - diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index f0084f5..9c272af 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -160,4 +160,18 @@ final public function deleteOrFail(bool $cascade = true): StateInterface return $entityManager->run(); } + + /** + * Prepares the current entity for deletion. + * + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + final public function remove(bool $cascade = true): EntityManagerInterface + { + /** @var EntityManager $entityManager */ + $entityManager = Facade::getEntityManager(); + + return $entityManager->delete($this, $cascade); + } } diff --git a/config/yii-bootstrap.php b/src/Bridge/Yii3/yii-bootstrap.php similarity index 100% rename from config/yii-bootstrap.php rename to src/Bridge/Yii3/yii-bootstrap.php diff --git a/tests/src/ActiveRecordTest.php b/tests/src/ActiveRecordTest.php index d199bc3..1d26a82 100644 --- a/tests/src/ActiveRecordTest.php +++ b/tests/src/ActiveRecordTest.php @@ -176,4 +176,28 @@ public function it_deletes_entity(): void $this::assertTrue($user->delete()->isSuccess()); $this::assertCount(1, User::findAll()); } + + /** + * @test + * + * @throws NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws Throwable + */ + #[Test] + public function it_deletes_multiple_entities_using_remove_method(): void + { + $userOne = User::find(1); + $userTwo = User::find(2); + + $userOne->remove(); + $userTwo->remove(); + + $this::assertCount(2, User::findAll()); + + $entityManager = Facade::getEntityManager(); + $this::assertTrue($entityManager->run()->isSuccess()); + + $this::assertCount(0, User::findAll()); + } } From ba5cd7fd87d5acd10b2af70a4fdd54afab909cc2 Mon Sep 17 00:00:00 2001 From: lotyp Date: Fri, 3 May 2024 19:28:39 +0300 Subject: [PATCH 2/2] chore: update lock-file --- composer.lock | 190 +++++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 94 deletions(-) diff --git a/composer.lock b/composer.lock index e87de6f..cf98a6b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "59cfc95164dd216ac36555a118bad70a", + "content-hash": "813e5b892d01bd8ad46eeeb36e615a22", "packages": [ { "name": "cocur/slugify", @@ -2423,6 +2423,73 @@ ], "time": "2024-04-18T09:29:19+00:00" }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.5.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-04-18T09:32:20+00:00" + }, { "name": "symfony/event-dispatcher", "version": "v7.0.7", @@ -2505,16 +2572,16 @@ }, { "name": "symfony/event-dispatcher-contracts", - "version": "v3.4.2", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "4e64b49bf370ade88e567de29465762e316e4224" + "reference": "8f93aec25d41b72493c6ddff14e916177c9efc50" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/4e64b49bf370ade88e567de29465762e316e4224", - "reference": "4e64b49bf370ade88e567de29465762e316e4224", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/8f93aec25d41b72493c6ddff14e916177c9efc50", + "reference": "8f93aec25d41b72493c6ddff14e916177c9efc50", "shasum": "" }, "require": { @@ -2524,7 +2591,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -2561,7 +2628,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.4.2" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.5.0" }, "funding": [ { @@ -2577,7 +2644,7 @@ "type": "tidelift" } ], - "time": "2024-01-23T14:51:35+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "symfony/finder", @@ -3441,21 +3508,22 @@ }, { "name": "symfony/service-contracts", - "version": "v3.4.2", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "11bbf19a0fb7b36345861e85c5768844c552906e" + "reference": "bd1d9e59a81d8fa4acdcea3f617c581f7475a80f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/11bbf19a0fb7b36345861e85c5768844c552906e", - "reference": "11bbf19a0fb7b36345861e85c5768844c552906e", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/bd1d9e59a81d8fa4acdcea3f617c581f7475a80f", + "reference": "bd1d9e59a81d8fa4acdcea3f617c581f7475a80f", "shasum": "" }, "require": { "php": ">=8.1", - "psr/container": "^1.1|^2.0" + "psr/container": "^1.1|^2.0", + "symfony/deprecation-contracts": "^2.5|^3" }, "conflict": { "ext-psr": "<1.1|>=2" @@ -3463,7 +3531,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -3503,7 +3571,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.4.2" + "source": "https://github.com/symfony/service-contracts/tree/v3.5.0" }, "funding": [ { @@ -3519,7 +3587,7 @@ "type": "tidelift" } ], - "time": "2023-12-19T21:51:00+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "symfony/string", @@ -3703,16 +3771,16 @@ }, { "name": "symfony/translation-contracts", - "version": "v3.4.2", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/translation-contracts.git", - "reference": "43810bdb2ddb5400e5c5e778e27b210a0ca83b6b" + "reference": "b9d2189887bb6b2e0367a9fc7136c5239ab9b05a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/43810bdb2ddb5400e5c5e778e27b210a0ca83b6b", - "reference": "43810bdb2ddb5400e5c5e778e27b210a0ca83b6b", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/b9d2189887bb6b2e0367a9fc7136c5239ab9b05a", + "reference": "b9d2189887bb6b2e0367a9fc7136c5239ab9b05a", "shasum": "" }, "require": { @@ -3721,7 +3789,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -3761,7 +3829,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/translation-contracts/tree/v3.4.2" + "source": "https://github.com/symfony/translation-contracts/tree/v3.5.0" }, "funding": [ { @@ -3777,7 +3845,7 @@ "type": "tidelift" } ], - "time": "2024-01-23T14:51:35+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "vlucas/phpdotenv", @@ -8809,12 +8877,12 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "a6cc84fe50abd91fdbfa06fa0e7b93386aa2193c" + "reference": "f9d568f4dfd55d0a2a306d67330dde426277e0dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/a6cc84fe50abd91fdbfa06fa0e7b93386aa2193c", - "reference": "a6cc84fe50abd91fdbfa06fa0e7b93386aa2193c", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/f9d568f4dfd55d0a2a306d67330dde426277e0dc", + "reference": "f9d568f4dfd55d0a2a306d67330dde426277e0dc", "shasum": "" }, "conflict": { @@ -9189,6 +9257,7 @@ "nonfiction/nterchange": "<4.1.1", "notrinos/notrinos-erp": "<=0.7", "noumo/easyii": "<=0.9", + "novaksolutions/infusionsoft-php-sdk": "<1", "nukeviet/nukeviet": "<4.5.02", "nyholm/psr7": "<1.6.1", "nystudio107/craft-seomatic": "<3.4.12", @@ -9592,7 +9661,7 @@ "type": "tidelift" } ], - "time": "2024-04-30T09:04:31+00:00" + "time": "2024-05-03T05:04:43+00:00" }, { "name": "sanmai/later", @@ -11077,73 +11146,6 @@ ], "time": "2024-04-18T09:29:19+00:00" }, - { - "name": "symfony/deprecation-contracts", - "version": "v3.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "files": [ - "function.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-05-23T14:45:45+00:00" - }, { "name": "symfony/filesystem", "version": "v7.0.7",