Skip to content

Commit 111a515

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent b4eb698 commit 111a515

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

Store/StoreFactory.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,38 @@ public static function createStore($connection)
6060
case 'flock' === $connection:
6161
return new FlockStore();
6262

63-
case 0 === strpos($connection, 'flock://'):
63+
case str_starts_with($connection, 'flock://'):
6464
return new FlockStore(substr($connection, 8));
6565

6666
case 'semaphore' === $connection:
6767
return new SemaphoreStore();
6868

69-
case 0 === strpos($connection, 'redis:'):
70-
case 0 === strpos($connection, 'rediss:'):
71-
case 0 === strpos($connection, 'memcached:'):
69+
case str_starts_with($connection, 'redis:'):
70+
case str_starts_with($connection, 'rediss:'):
71+
case str_starts_with($connection, 'memcached:'):
7272
if (!class_exists(AbstractAdapter::class)) {
7373
throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection));
7474
}
75-
$storeClass = 0 === strpos($connection, 'memcached:') ? MemcachedStore::class : RedisStore::class;
75+
$storeClass = str_starts_with($connection, 'memcached:') ? MemcachedStore::class : RedisStore::class;
7676
$connection = AbstractAdapter::createConnection($connection, ['lazy' => true]);
7777

7878
return new $storeClass($connection);
7979

80-
case 0 === strpos($connection, 'mssql://'):
81-
case 0 === strpos($connection, 'mysql:'):
82-
case 0 === strpos($connection, 'mysql2://'):
83-
case 0 === strpos($connection, 'oci:'):
84-
case 0 === strpos($connection, 'oci8://'):
85-
case 0 === strpos($connection, 'pdo_oci://'):
86-
case 0 === strpos($connection, 'pgsql:'):
87-
case 0 === strpos($connection, 'postgres://'):
88-
case 0 === strpos($connection, 'postgresql://'):
89-
case 0 === strpos($connection, 'sqlsrv:'):
90-
case 0 === strpos($connection, 'sqlite:'):
91-
case 0 === strpos($connection, 'sqlite3://'):
80+
case str_starts_with($connection, 'mssql://'):
81+
case str_starts_with($connection, 'mysql:'):
82+
case str_starts_with($connection, 'mysql2://'):
83+
case str_starts_with($connection, 'oci:'):
84+
case str_starts_with($connection, 'oci8://'):
85+
case str_starts_with($connection, 'pdo_oci://'):
86+
case str_starts_with($connection, 'pgsql:'):
87+
case str_starts_with($connection, 'postgres://'):
88+
case str_starts_with($connection, 'postgresql://'):
89+
case str_starts_with($connection, 'sqlsrv:'):
90+
case str_starts_with($connection, 'sqlite:'):
91+
case str_starts_with($connection, 'sqlite3://'):
9292
return new PdoStore($connection);
9393

94-
case 0 === strpos($connection, 'zookeeper://'):
94+
case str_starts_with($connection, 'zookeeper://'):
9595
return new ZookeeperStore(ZookeeperStore::createConnection($connection));
9696
}
9797

Store/ZookeeperStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(\Zookeeper $zookeeper)
3737

3838
public static function createConnection(string $dsn): \Zookeeper
3939
{
40-
if (0 !== strpos($dsn, 'zookeeper:')) {
40+
if (!str_starts_with($dsn, 'zookeeper:')) {
4141
throw new InvalidArgumentException(sprintf('Unsupported DSN: "%s".', $dsn));
4242
}
4343

@@ -153,7 +153,7 @@ private function getKeyResource(Key $key): string
153153
// For example: foo/bar will become /foo-bar and /foo/bar will become /-foo-bar
154154
$resource = (string) $key;
155155

156-
if (false !== strpos($resource, '/')) {
156+
if (str_contains($resource, '/')) {
157157
$resource = strtr($resource, ['/' => '-']).'-'.sha1($resource);
158158
}
159159

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
],
1818
"require": {
1919
"php": ">=7.1.3",
20-
"psr/log": "^1|^2|^3"
20+
"psr/log": "^1|^2|^3",
21+
"symfony/polyfill-php80": "^1.16"
2122
},
2223
"require-dev": {
2324
"doctrine/dbal": "^2.6|^3.0",

0 commit comments

Comments
 (0)