Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use some more phpstan-friendly pregging #1356

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function get_db(): PDO

private function connect_engine(): void
{
if (\Safe\preg_match("/^([^:]*)/", $this->dsn, $matches)) {
if (preg_match("/^([^:]*)/", $this->dsn, $matches)) {
$db_proto = $matches[1];
} else {
throw new ServerError("Can't figure out database engine");
Expand Down
2 changes: 1 addition & 1 deletion core/dbengine.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function create_table_sql(string $name, string $data): string
$extras = "";
foreach (explode(",", $data) as $bit) {
$matches = [];
if (\Safe\preg_match("/(UNIQUE)? ?INDEX\s*\((.*)\)/", $bit, $matches)) {
if (preg_match("/(UNIQUE)? ?INDEX\s*\((.*)\)/", $bit, $matches)) {
$uni = $matches[1];
$col = $matches[2];
$extras .= "CREATE $uni INDEX {$name}_{$col} ON {$name}({$col});";
Expand Down
5 changes: 1 addition & 4 deletions core/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,7 @@ public static function is_active(array $pages_matched, ?string $url = null): boo
*/
$url = $url ?? _get_query();

$re1 = '.*?';
$re2 = '((?:[a-z][a-z_]+))';

if (\Safe\preg_match_all("/".$re1.$re2."/is", $url, $matches)) {
if (preg_match_all("/.*?((?:[a-z][a-z_]+))/is", $url, $matches) > 0) {
$url = $matches[1][0];
}

Expand Down
2 changes: 0 additions & 2 deletions core/polyfills.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Shimmie2;

use function Safe\preg_match;

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Things which should be in the core API *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down
4 changes: 2 additions & 2 deletions core/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ function path_to_tags(string $path): array
{
$matches = [];
$tags = [];
if (\Safe\preg_match("/\d+ - (.+)\.([a-zA-Z0-9]+)/", basename($path), $matches)) {
if (preg_match("/\d+ - (.+)\.([a-zA-Z0-9]+)/", basename($path), $matches)) {
$tags = explode(" ", $matches[1]);
}

Expand Down Expand Up @@ -812,7 +812,7 @@ function shm_tempnam(string $prefix = ""): string
function load_balance_url(string $tmpl, string $hash, int $n = 0): string
{
$matches = [];
if (\Safe\preg_match("/(.*){(.*)}(.*)/", $tmpl, $matches)) {
if (preg_match("/(.*){(.*)}(.*)/", $tmpl, $matches)) {
$pre = $matches[1];
$opts = $matches[2];
$post = $matches[3];
Expand Down
2 changes: 1 addition & 1 deletion ext/ban_words/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function test_text(string $comment, SCoreException $ex): void
foreach ($this->get_words() as $word) {
if ($word[0] == '/') {
// lines that start with slash are regex
if (\Safe\preg_match($word, $comment) === 1) {
if (\Safe\preg_match($word, $comment)) {
throw $ex;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion ext/index/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function matches(string $regex): ?array
if (is_null($this->term)) {
return null;
}
if (\Safe\preg_match($regex, $this->term, $matches) === 1) {
if (\Safe\preg_match($regex, $this->term, $matches)) {
return $matches;
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion ext/link_image/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function testLinkImage(): void
$this->get_page("post/view/$image_id");

$matches = [];
\Safe\preg_match("#value='https?://.*/(post/view/[0-9]+)'#", $this->page_to_text(), $matches);
$this->assertNotFalse(preg_match("#value='https?://.*/(post/view/[0-9]+)'#", $this->page_to_text(), $matches));
$this->assertNotEmpty($matches);
$page = $this->get_page($matches[1]);
$this->assertEquals("Post $image_id: pie", $page->title);
Expand Down
5 changes: 2 additions & 3 deletions ext/media/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,8 @@ public static function video_size(string $filename): array
}
// error_log("Getting size with `$cmd`");

$regex_sizes = "/Video: .* ([0-9]{1,4})x([0-9]{1,4})/";
if (\Safe\preg_match($regex_sizes, $output, $regs)) {
if (\Safe\preg_match("/displaymatrix: rotation of (90|270).00 degrees/", $output)) {
if (preg_match("/Video: .* ([0-9]{1,4})x([0-9]{1,4})/", $output, $regs)) {
if (preg_match("/displaymatrix: rotation of (90|270).00 degrees/", $output)) {
$size = [(int)$regs[2], (int)$regs[1]];
} else {
$size = [(int)$regs[1], (int)$regs[2]];
Expand Down
4 changes: 2 additions & 2 deletions ext/ouroboros_api/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function onPageRequest(PageRequestEvent $event): void
{
global $page, $user;

if (\Safe\preg_match("%\.(xml|json)$%", implode('/', $event->args), $matches) === 1) {
if (preg_match("%\.(xml|json)$%", implode('/', $event->args), $matches)) {
$this->type = $matches[1];
if ($this->type == 'json') {
$page->set_mime('application/json; charset=utf-8');
Expand Down Expand Up @@ -617,6 +617,6 @@ private function tryAuth(): void
*/
private function match(PageRequestEvent $event, string $page): bool
{
return (\Safe\preg_match("%{$page}\.(xml|json)$%", implode('/', $event->args), $matches) === 1);
return (preg_match("%{$page}\.(xml|json)$%", implode('/', $event->args), $matches) === 1);
}
}
4 changes: 2 additions & 2 deletions ext/post_tags/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct(string $term)
public function matches(string $regex): ?array
{
$matches = [];
if (\Safe\preg_match($regex, $this->term, $matches) === 1) {
if (\Safe\preg_match($regex, $this->term, $matches)) {
return $matches;
}
return null;
Expand Down Expand Up @@ -108,7 +108,7 @@ public function __construct(string $term, int $image_id)
public function matches(string $regex): ?array
{
$matches = [];
if (\Safe\preg_match($regex, $this->term, $matches) === 1) {
if (\Safe\preg_match($regex, $this->term, $matches)) {
return array_values($matches);
}
return null;
Expand Down