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

adapt constant expressions #447

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 3 additions & 3 deletions src/Aimeos/Shop/Base/Support.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ public function __construct( \Aimeos\Shop\Base\Context $context, \Aimeos\Shop\Ba
*/
public function checkUserGroup( \Illuminate\Foundation\Auth\User $user, $groupcodes ) : bool
{
$groups = ( is_array( $groupcodes ) ? implode( ',', $groupcodes ) : $groupcodes );
$groups = ( \is_array( $groupcodes ) ? implode( ',', $groupcodes ) : $groupcodes );

if( isset( $this->access[$user->id][$groups] ) ) {
return $this->access[$user->id][$groups];
}

$this->access[$user->id][$groups] = false;

if( $siteid = current( array_reverse( explode( '.', trim( $user->siteid, '.' ) ) ) ) )
if( $siteid = current( \array_reverse( explode( '.', trim( $user->siteid, '.' ) ) ) ) )
{
$context = $this->context->get( false );
$site = \Aimeos\MShop::create( $context, 'locale/site' )->get( $siteid )->getCode();
$site = ( Route::current() ? Route::input( 'site', Request::get( 'site', $site ) ) : $site );

$context->setLocale( $this->locale->getBackend( $context, $site ) );

foreach( array_reverse( $context->locale()->getSitePath() ) as $siteid )
foreach( \array_reverse( $context->locale()->getSitePath() ) as $siteid )
{
if( (string) $user->siteid === (string) $siteid ) {
$this->access[$user->id][$groups] = $this->checkGroups( $context, $user->id, $groupcodes );
Expand Down
4 changes: 2 additions & 2 deletions src/Aimeos/Shop/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function exec( \Aimeos\MShop\Context\Item\Iface $context, \Closure $fc
$start = 0;

if( !empty( $sites ) ) {
$filter->add( ['locale.site.code' => !is_array( $sites ) ? explode( ' ', (string) $sites ) : $sites] );
$filter->add( [ 'locale.site.code' => \is_array( $sites ) ? $sites : explode( ' ', (string) $sites ) ] );
}

do
Expand Down Expand Up @@ -67,7 +67,7 @@ protected function exec( \Aimeos\MShop\Context\Item\Iface $context, \Closure $fc
$process->start( $fcn, [$lcontext, $aimeos], false );
}

$count = count( $siteItems );
$count = \count( $siteItems );
$start += $count;
}
while( $count === $filter->getLimit() );
Expand Down
2 changes: 1 addition & 1 deletion src/Aimeos/Shop/Command/AccountCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function addGroup( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\
$this->info( sprintf( $msg, $group, $user->getCode(), $this->argument( 'site' ) ) );

$groupId = $this->getGroupItem( $context, $group )->getId();
return $user->setGroups( array_merge( $user->getGroups(), [$groupId] ) );
return $user->setGroups( \array_merge( $user->getGroups(), [$groupId] ) );
}


Expand Down
2 changes: 1 addition & 1 deletion src/Aimeos/Shop/Command/JobsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class JobsCommand extends AbstractCommand
public function handle()
{
$jobs = $this->argument( 'jobs' );
$jobs = !is_array( $jobs ) ? explode( ' ', (string) $jobs ) : $jobs;
$jobs = \is_array( $jobs ) ? $jobs : explode( ' ', (string) $jobs );

$fcn = function( \Aimeos\MShop\Context\Item\Iface $lcontext, \Aimeos\Bootstrap $aimeos ) use ( $jobs )
{
Expand Down
2 changes: 1 addition & 1 deletion src/Aimeos/Shop/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function indexAction( \Illuminate\Http\Request $request )

$context = app( 'aimeos.context' )->get( false );
$siteManager = \Aimeos\MShop::create( $context, 'locale/site' );
$siteId = current( array_reverse( explode( '.', trim( $request->user()->siteid, '.' ) ) ) );
$siteId = current( \array_reverse( explode( '.', trim( $request->user()->siteid, '.' ) ) ) );
$siteCode = ( $siteId ? $siteManager->get( $siteId )->getCode() : 'default' );
$locale = $request->user()->langid ?: config( 'app.locale', 'en' );

Expand Down
4 changes: 2 additions & 2 deletions src/Aimeos/Shop/Controller/JqadmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function fileAction()
{
$jsbAbsPath = $base . '/' . $path;
$jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $jsbAbsPath ) );
$files = array_merge( $files, $jsb2->getFiles( $type ) );
$files = \array_merge( $files, $jsb2->getFiles( $type ) );
}
}

Expand Down Expand Up @@ -264,7 +264,7 @@ protected function getHtml( string $content )
'content' => $content,
'site' => $site,
'locale' => $lang,
'localeDir' => in_array( $lang, ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur'] ) ? 'rtl' : 'ltr',
'localeDir' => \in_array( $lang, ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur'] ) ? 'rtl' : 'ltr',
'theme' => ( $_COOKIE['aimeos_backend_theme'] ?? '' ) == 'dark' ? 'dark' : 'light'
] );
}
Expand Down
4 changes: 2 additions & 2 deletions src/Aimeos/Shop/Controller/JsonadmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function deleteAction( ServerRequestInterface $request )
public function getAction( ServerRequestInterface $request )
{
if( config( 'shop.authorize', true ) ) {
$this->authorize( 'admin', [JsonadmController::class, array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] );
$this->authorize( 'admin', [JsonadmController::class, \array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] );
}

return $this->createAdmin()->get( $request, ( new Psr17Factory )->createResponse() );
Expand Down Expand Up @@ -118,7 +118,7 @@ public function putAction( ServerRequestInterface $request )
public function optionsAction( ServerRequestInterface $request )
{
if( config( 'shop.authorize', true ) ) {
$this->authorize( 'admin', [JsonadmController::class, array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] );
$this->authorize( 'admin', [JsonadmController::class, \array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] );
}

return $this->createAdmin()->options( $request, ( new Psr17Factory )->createResponse() );
Expand Down
4 changes: 2 additions & 2 deletions src/views/base.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html class="no-js" lang="{{ str_replace('_', '-', app()->getLocale()) }}" dir="{{ in_array(app()->getLocale(), ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur']) ? 'rtl' : 'ltr' }}">
<html class="no-js" lang="{{ str_replace('_', '-', app()->getLocale()) }}" dir="{{ \in_array(app()->getLocale(), ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur']) ? 'rtl' : 'ltr' }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="base-uri 'self'; default-src 'self' 'nonce-{{ app( 'aimeos.context' )->get()->nonce() }}'; style-src 'unsafe-inline' 'self'; img-src 'self' data: https://aimeos.org; frame-src https://www.youtube.com https://player.vimeo.com">
<meta name="csrf-token" content="{{ csrf_token() }}">

@if( in_array(app()->getLocale(), ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur']) )
@if( \in_array(app()->getLocale(), ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur']) )
<link type="text/css" rel="stylesheet" href="{{ asset('vendor/shop/themes/default/app.rtl.css?v=' . config( 'shop.version', 1 ) ) }}">
@else
<link type="text/css" rel="stylesheet" href="{{ asset('vendor/shop/themes/default/app.css?v=' . config( 'shop.version', 1 ) ) }}">
Expand Down
18 changes: 9 additions & 9 deletions tests/Controller/JsonadmControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testOptionsAction()
$this->assertNotNull( $json );
$this->assertEquals( 200, $response->getStatusCode() );
$this->assertArrayHasKey( 'resources', $json['meta'] );
$this->assertGreaterThan( 1, count( $json['meta']['resources'] ) );
$this->assertGreaterThan( 1, \count( $json['meta']['resources'] ) );


$params = ['site' => 'unittest'];
Expand All @@ -41,7 +41,7 @@ public function testOptionsAction()
$this->assertNotNull( $json );
$this->assertEquals( 200, $response->getStatusCode() );
$this->assertArrayHasKey( 'resources', $json['meta'] );
$this->assertGreaterThan( 1, count( $json['meta']['resources'] ) );
$this->assertGreaterThan( 1, \count( $json['meta']['resources'] ) );
}


Expand Down Expand Up @@ -122,7 +122,7 @@ public function testActionsBulk()

$this->assertEquals( 201, $response->getStatusCode() );
$this->assertNotNull( $json );
$this->assertEquals( 2, count( $json['data'] ) );
$this->assertEquals( 2, \count( $json['data'] ) );
$this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] );
$this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] );
$this->assertEquals( 'laravel', $json['data'][0]['attributes']['stock.type.label'] );
Expand All @@ -143,13 +143,13 @@ public function testActionsBulk()

$this->assertResponseOk();
$this->assertNotNull( $json );
$this->assertEquals( 2, count( $json['data'] ) );
$this->assertEquals( 2, \count( $json['data'] ) );
$this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] );
$this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] );
$this->assertEquals( 'laravel2', $json['data'][0]['attributes']['stock.type.label'] );
$this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.label'] );
$this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) );
$this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) );
$this->assertTrue( \in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) );
$this->assertTrue( \in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) );
$this->assertEquals( 2, $json['meta']['total'] );


Expand All @@ -166,13 +166,13 @@ public function testActionsBulk()

$this->assertResponseOk();
$this->assertNotNull( $json );
$this->assertEquals( 2, count( $json['data'] ) );
$this->assertEquals( 2, \count( $json['data'] ) );
$this->assertEquals( 'laravel', $json['data'][0]['attributes']['stock.type.code'] );
$this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.code'] );
$this->assertEquals( 'laravel2', $json['data'][0]['attributes']['stock.type.label'] );
$this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.label'] );
$this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) );
$this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) );
$this->assertTrue( \in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) );
$this->assertTrue( \in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) );
$this->assertEquals( 2, $json['meta']['total'] );


Expand Down
6 changes: 3 additions & 3 deletions tests/Controller/JsonapiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testOptionsAction()
$this->assertNotNull( $json );
$this->assertEquals( 200, $response->getStatusCode() );
$this->assertArrayHasKey( 'resources', $json['meta'] );
$this->assertGreaterThan( 1, count( $json['meta']['resources'] ) );
$this->assertGreaterThan( 1, \count( $json['meta']['resources'] ) );
}


Expand All @@ -31,7 +31,7 @@ public function testGetAction()
$this->assertResponseOk();
$this->assertNotNull( $json );
$this->assertEquals( 3, $json['meta']['total'] );
$this->assertEquals( 3, count( $json['data'] ) );
$this->assertEquals( 3, \count( $json['data'] ) );
$this->assertArrayHasKey( 'id', $json['data'][0] );
$this->assertEquals( 'CNC', $json['data'][0]['attributes']['product.code'] );

Expand Down Expand Up @@ -84,7 +84,7 @@ public function testPostPatchDeleteAction()
$response = $this->action( 'DELETE', '\Aimeos\Shop\Controller\JsonapiController@deleteAction', $params );

$json = json_decode( $response->getContent(), true );
$this->assertEquals( 0, count( $json['included'] ) );
$this->assertEquals( 0, \count( $json['included'] ) );
}


Expand Down