Issues (15)

tests/TestAddressChangeContextFactory.php (2 issues)

1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\AddressChangeContext\Tests;
6
7
use Doctrine\DBAL\Connection;
8
use Doctrine\DBAL\DriverManager;
9
use Doctrine\ORM\Configuration;
10
use Doctrine\ORM\EntityManager;
11
use Doctrine\ORM\ORMSetup;
12
use WMDE\Fundraising\AddressChangeContext\AddressChangeContextFactory;
13
14
/**
15
 * @phpstan-import-type Params from DriverManager
16
 */
17
class TestAddressChangeContextFactory {
18
19
	private Configuration $doctrineConfig;
20
	private ?EntityManager $entityManager;
21
	private AddressChangeContextFactory $contextFactory;
22
23
	/**
24
	 * @param Params $config
0 ignored issues
show
The type WMDE\Fundraising\AddressChangeContext\Tests\Params was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
	 */
26
	public function __construct( private readonly array $config ) {
27
		$this->contextFactory = new AddressChangeContextFactory();
28
		$this->doctrineConfig = ORMSetup::createXMLMetadataConfiguration(
29
			$this->contextFactory->getDoctrineMappingPaths(),
30
			true
31
		);
32
		$this->entityManager = null;
33
	}
34
35
	private function newConnection(): Connection {
36
		$connection = DriverManager::getConnection( $this->config );
37
		$this->contextFactory->registerCustomTypes( $connection );
38
		return $connection;
39
	}
40
41
	public function newEntityManager(): EntityManager {
42
		return new EntityManager( $this->newConnection(), $this->doctrineConfig );
43
	}
44
45
	public function getEntityManager(): EntityManager {
46
		if ( $this->entityManager === null ) {
47
			$this->entityManager = $this->newEntityManager();
48
		}
49
		return $this->entityManager;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->entityManager could return the type null which is incompatible with the type-hinted return Doctrine\ORM\EntityManager. Consider adding an additional type-check to rule them out.
Loading history...
50
	}
51
}
52