Skip to content

Feature/phpstan upgrade #434

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

Merged
merged 4 commits into from
Mar 26, 2025
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
33 changes: 14 additions & 19 deletions includes/MslsOptionsTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,42 @@ class MslsOptionsTax extends MslsOptions implements OptionsTaxInterface {
* @return OptionsTaxInterface
*/
public static function create( $id = 0 ): OptionsTaxInterface {
$id = ! empty( $id ) ? (int) $id : get_queried_object_id();

$req = '';
if ( is_admin() ) {
$req = msls_content_types()->acl_request();
} elseif ( is_category() ) {
$req = 'category';
} elseif ( is_tag( $id ) ) {
$req = 'post_tag';
}
$id = ! empty( $id ) ? (int) $id : get_queried_object_id();
$req = self::get_content_type( $id );

switch ( $req ) {
case 'category':
$options = new MslsOptionsTaxTermCategory( $id );
add_filter( 'msls_get_postlink', array( $options, 'check_base' ), 9, 2 );
break;
case 'post_tag':
$options = new MslsOptionsTaxTerm( $id );
add_filter( 'msls_get_postlink', array( $options, 'check_base' ), 9, 2 );
break;
default:
global $wp_rewrite;

$options = new MslsOptionsTax( $id );
$options->with_front = ! empty( $wp_rewrite->extra_permastructs[ $options->get_tax_query() ]['with_front'] );
$options = new MslsOptionsTax( $id );
}

return $options;
return $options->handle_rewrite();
}

/**
* @param int $id
*
* @return string
*/
public function get_content_type( int $id ): string {
public static function get_content_type( int $id ): string {
if ( is_admin() ) {
return msls_content_types()->acl_request();
}

return ( is_category() ? 'category' : is_tag( $id ) ) ? 'post_tag' : '';
return ( is_category( $id ) ? 'category' : ( is_tag( $id ) ? 'post_tag' : '' ) );
}

public function handle_rewrite(): OptionsTaxInterface {
global $wp_rewrite;

$this->with_front = ! empty( $wp_rewrite->extra_permastructs[ $this->get_tax_query() ]['with_front'] );

return $this;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions includes/MslsOptionsTaxTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class MslsOptionsTaxTerm extends MslsOptionsTax implements OptionsTaxInterface {
*/
public ?bool $with_front = true;

public function handle_rewrite(): OptionsTaxInterface {
add_filter( 'msls_get_postlink', array( $this, 'check_base' ), 9, 2 );

return $this;
}

/**
* Check and correct URL
*
Expand Down
2 changes: 2 additions & 0 deletions includes/OptionsTaxInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
interface OptionsTaxInterface extends OptionsInterface {

public static function get_base_option(): string;

public function handle_rewrite(): OptionsTaxInterface;
}
4 changes: 2 additions & 2 deletions tests/phpunit/TestMslsOptionsTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ final class TestMslsOptionsTax extends MslsUnitTestCase {
private function MslsOptionsTaxFactory(): MslsOptionsTax {
Functions\expect( 'get_option' )->atLeast()->once()->andReturn( array( 'de_DE' => 42 ) );

return new MslsOptionsTax( 0 );
return new MslsOptionsTax();
}

public function test_create_category(): void {
Functions\expect( 'get_queried_object_id' )->once()->andReturn( 42 );
Functions\expect( 'is_admin' )->once()->andReturnFalse();
Functions\expect( 'is_category' )->once()->andReturnTrue();
Functions\expect( 'is_category' )->once()->with( 42 )->andReturnTrue();
Functions\expect( 'get_option' )->atLeast()->once()->andReturn( array( 'de_DE' => 42 ) );

$this->assertInstanceOf( MslsOptionsTaxTermCategory::class, MslsOptionsTax::create() );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/TestMslsPostTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function test_edit_input(): void {
$taxonomy = \Mockery::mock( MslsTaxonomy::class );
$taxonomy->shouldReceive( 'is_taxonomy' )->atLeast()->once()->andReturn( true );
$taxonomy->shouldReceive( 'get_request' )->atLeast()->once()->andReturn( 'post' );
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( array( 'taxonomy', 'post_tag' ) );
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( 'taxonomy' );

$term = \Mockery::mock( \WP_Term::class );
$term->name = 'test-term-name';
Expand Down Expand Up @@ -140,7 +140,7 @@ public function test_add_input(): void {
$taxonomy = \Mockery::mock( MslsTaxonomy::class );
$taxonomy->shouldReceive( 'is_taxonomy' )->atLeast()->once()->andReturnTrue();
$taxonomy->shouldReceive( 'get_request' )->atLeast()->once()->andReturn( 'post' );
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( array( 'taxonomy', 'post_tag' ) );
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( 'taxonomy' );

Functions\expect( 'msls_content_types' )->atLeast()->once()->andReturn( $taxonomy );
Functions\expect( 'get_queried_object_id' )->atLeast()->once()->andReturn( 42 );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/TestMslsPostTagClassic.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function test_edit_input(): void {
Functions\expect( 'get_edit_term_link' )->atLeast()->once()->andReturn( 'edit_term_link' );

$taxonomy = \Mockery::mock( \WP_Taxonomy::class );
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( array( 'taxonomy', 'post_type' ) );
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( 'taxonomy' );
$taxonomy->shouldReceive( 'is_taxonomy' )->atLeast()->once()->andReturnTrue();
$taxonomy->shouldReceive( 'get_request' )->atLeast()->once()->andReturn( 'post_type' );

Expand Down Expand Up @@ -133,7 +133,7 @@ public function test_add_input(): void {
Functions\expect( 'get_edit_term_link' )->atLeast()->once()->andReturn( 'edit_term_link' );

$taxonomy = \Mockery::mock( \WP_Taxonomy::class );
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( array( 'taxonomy', 'post_type' ) );
$taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( 'taxonomy' );
$taxonomy->shouldReceive( 'is_taxonomy' )->atLeast()->once()->andReturnTrue();
$taxonomy->shouldReceive( 'get_request' )->atLeast()->once()->andReturn( 'post_type' );

Expand Down
Loading