Skip to content

Commit

Permalink
formatting. renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jul 9, 2019
1 parent 70562f5 commit 69de466
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 53 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Auth/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function denies($ability, $arguments = [])
public function check($abilities, $arguments = [])
{
return collect($abilities)->every(function ($ability) use ($arguments) {
return $this->access($ability, $arguments)->allowed();
return $this->inspect($ability, $arguments)->allowed();
});
}

Expand Down Expand Up @@ -315,17 +315,17 @@ public function none($abilities, $arguments = [])
*/
public function authorize($ability, $arguments = [])
{
return $this->access($ability, $arguments)->authorize();
return $this->inspect($ability, $arguments)->authorize();
}

/**
* Get the access response for the given ability.
* Inspect the user for the given ability.
*
* @param string $ability
* @param array|mixed $arguments
* @return \Illuminate\Auth\Access\Response
*/
public function access($ability, $arguments = [])
public function inspect($ability, $arguments = [])
{
try {
$result = $this->raw($ability, $arguments);
Expand Down
84 changes: 42 additions & 42 deletions src/Illuminate/Auth/Access/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
class Response implements Arrayable
{
/**
* The response message.
* Indicates whether the response was allowed.
*
* @var string|null
* @var bool
*/
protected $message;
protected $allowed;

/**
* Indicates whether the response was allowed.
* The response message.
*
* @var bool
* @var string|null
*/
protected $allowed;
protected $message;

/**
* The response code.
Expand All @@ -30,26 +30,40 @@ class Response implements Arrayable
/**
* Create a new response.
*
* @param string $message
* @param bool $allowed
* @param mixed $code
* @param bool $allowed
* @param string $message
* @param mixed $code
* @return void
*/
public function __construct($message, bool $allowed, $code = null)
public function __construct(bool $allowed, $message = '', $code = null)
{
$this->message = $message;
$this->allowed = $allowed;
$this->code = $code;
$this->allowed = $allowed;
$this->message = $message;
}

/**
* Get the response message.
* Create a new "allow" Response.
*
* @return string|null
* @param string|null $message
* @param mixed $code
* @return \Illuminate\Auth\Access\Response
*/
public function message()
public static function allow($message = null, $code = null)
{
return $this->message;
return new static(true, $message, $code);
}

/**
* Create a new "deny" Response.
*
* @param string|null $message
* @param mixed $code
* @return \Illuminate\Auth\Access\Response
*/
public static function deny($message = 'This action is unauthorized.', $code = null)
{
return new static(false, $message, $code);
}

/**
Expand All @@ -73,23 +87,23 @@ public function denied()
}

/**
* Get the response code/reason.
* Get the response message.
*
* @return mixed
* @return string|null
*/
public function code()
public function message()
{
return $this->code;
return $this->message;
}

/**
* Get the string representation of the message.
* Get the response code / reason.
*
* @return string
* @return mixed
*/
public function __toString()
public function code()
{
return (string) $this->message();
return $this->code;
}

/**
Expand Down Expand Up @@ -123,26 +137,12 @@ public function toArray()
}

/**
* Create a new "allow" Response.
*
* @param string|null $message
* @param mixed $code
* @return \Illuminate\Auth\Access\Response
*/
public static function allow($message = null, $code = null)
{
return new static($message, true, $code);
}

/**
* Create a new "deny" Response.
* Get the string representation of the message.
*
* @param string|null $message
* @param mixed $code
* @return \Illuminate\Auth\Access\Response
* @return string
*/
public static function deny($message = 'This action is unauthorized.', $code = null)
public function __toString()
{
return new static($message, false, $code);
return (string) $this->message();
}
}
4 changes: 2 additions & 2 deletions src/Illuminate/Contracts/Auth/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public function any($abilities, $arguments = []);
public function authorize($ability, $arguments = []);

/**
* Get the access response for the given ability.
* Inspect the user for the given ability.
*
* @param string $ability
* @param array|mixed $arguments
* @return \Illuminate\Auth\Access\Response
*/
public function access($ability, $arguments = []);
public function inspect($ability, $arguments = []);

/**
* Get the raw result from the authorization callback.
Expand Down
4 changes: 2 additions & 2 deletions tests/Auth/AuthAccessGateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public function test_response_returns_response_when_ability_granted()

$gate->policy(AccessGateTestDummy::class, AccessGateTestPolicyWithCode::class);

$response = $gate->access('view', new AccessGateTestDummy);
$response = $gate->inspect('view', new AccessGateTestDummy);

$this->assertInstanceOf(Response::class, $response);
$this->assertNull($response->message());
Expand All @@ -643,7 +643,7 @@ public function test_response_returns_response_when_ability_denied()

$gate->policy(AccessGateTestDummy::class, AccessGateTestPolicyWithCode::class);

$response = $gate->access('view', new AccessGateTestDummy);
$response = $gate->inspect('view', new AccessGateTestDummy);

$this->assertInstanceOf(Response::class, $response);
$this->assertEquals('Not allowed to view as it is not published.', $response->message());
Expand Down
6 changes: 3 additions & 3 deletions tests/Auth/AuthAccessResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ public function test_throw_if_needed_doesnt_throw_authorization_exception_when_r

public function test_casting_to_string_returns_message()
{
$response = new Response('some data', true);
$response = new Response(true, 'some data');
$this->assertSame('some data', (string) $response);

$response = new Response(null, false);
$response = new Response(false, null);
$this->assertSame('', (string) $response);
}

public function test_response_to_array_method()
{
$response = new Response('Not allowed.', false, 'some_code');
$response = new Response(false, 'Not allowed.', 'some_code');

$this->assertEquals([
'allowed' => false,
Expand Down

0 comments on commit 69de466

Please sign in to comment.