Skip to content

Commit

Permalink
Remove redundant legacy code/versions
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Mar 23, 2024
1 parent c195a1f commit 435fa27
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 27 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"symfony/twig-bridge": "^6.0 || ^7.0",
"symfony/var-dumper": "^6.0 || ^7.0",
"symfony/process": "^6.0 || ^7.0",
"twig/twig": "^1.26 || ^2.0 || ^3.0",
"vimeo/psalm": "^3.18.2 || ^4.0 || ^5.0",
"psalm/plugin-symfony": "^1.5.0 || ^2.0 || ^3.0 || ^4.0 || ^5.0"
"twig/twig": "^2.0 || ^3.0",
"vimeo/psalm": "^5.0",
"psalm/plugin-symfony": "^5.0"
},
"conflict": {
"illuminate/console": ">=9.21,<9.39"
"nesbot/carbon": "<2.63"
},

"autoload": { "psr-4": { "WouterJ\\EloquentBundle\\": "src" } },
Expand Down
3 changes: 1 addition & 2 deletions src/DataCollector/EloquentDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ public function __construct(Manager $capsule, QueryListener $queryListener)

public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
{
/** @psalm-suppress UndefinedInterfaceMethod */
$connections = array_map(function ($config) {
return $this->cloneVar($config);
}, $this->capsule->getContainer()['config']['database.connections']);
}, $this->capsule->getContainer()->make('config')['database.connections']);

$usedConnections = [];
foreach (array_keys($this->capsule->getDatabaseManager()->getConnections()) as $name) {
Expand Down
8 changes: 1 addition & 7 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('wouterj_eloquent');
/** @psalm-suppress RedundantCondition */
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
/** @psalm-suppress UndefinedMethod */
$root = $treeBuilder->root('wouterj_eloquent');
}
$root = $treeBuilder->getRootNode();

$this->addAliasesSection($root);
$this->addCapsuleSection($root);
Expand Down
4 changes: 1 addition & 3 deletions src/Factory/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
use Illuminate\Database\Eloquent\Model;

/**
* @psalm-suppress TooManyTemplateParams BC with Laravel 8
* @template TModel of Model
* @extends IlluminateFactory<TModel>
*/
abstract class Factory extends IlluminateFactory
{
public function modelName(): string
{
/** @psalm-suppress RedundantPropertyInitializationCheck */
$resolver = static::$modelNameResolver ?? function (self $factory) {
$resolver = static::$modelNameResolver ?: function (self $factory) {
$name = $factory::class;
if (str_ends_with($name, 'Factory')) {
$name = substr($name, 0, -7);
Expand Down
3 changes: 1 addition & 2 deletions src/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public function __construct(MigrationRepositoryInterface $repository, Resolver $
// BC with Laravel <10
$this->repository = $repository;
$this->resolver = $resolver;
/** @psalm-suppress InvalidPropertyAssignmentValue */
$this->files = new class {
$this->files = new class extends Filesystem {
public function getRequire($path, array $data = [])
{
if (is_file($path)) {
Expand Down
20 changes: 11 additions & 9 deletions tests/DataCollector/EloquentDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace WouterJ\EloquentBundle\DataCollector;

use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager;
use Illuminate\Support\Fluent;
use WouterJ\EloquentBundle\MockeryTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -21,14 +23,18 @@ class EloquentDataCollectorTest extends TestCase
{
use MockeryTrait;

private Container $container;
private $capsule;
private $queryListener;
private $collector;

protected function setUp(): void
{
$this->container = new Container();
$this->container->instance('config', new Fluent(['database.connections' => []]));

$this->capsule = \Mockery::mock(Manager::class);
$this->capsule->allows()->getContainer()->andReturn(['config' => ['database.connections' => []]])->byDefault();
$this->capsule->allows()->getContainer()->andReturn($this->container);
$this->capsule->allows()->getDatabaseManager()->andReturn(new class{
public function getConnections() { return []; }
})->byDefault();
Expand All @@ -42,14 +48,10 @@ public function getConnections() { return []; }
/** @test */
public function it_collects_connections()
{
$this->capsule->allows()->getContainer()->andReturn([
'config' => [
'database.connections' => [
'db1' => ['db' => 'foobar'],
'db2' => ['db' => 'something else']
],
],
]);
$this->container['config']['database.connections'] = [
'db1' => ['db' => 'foobar'],
'db2' => ['db' => 'something else']
];

$this->capsule->allows()->getDatabaseManager()->andReturn(new class{
public function getConnections() {
Expand Down

0 comments on commit 435fa27

Please sign in to comment.