Skip to content

Commit

Permalink
#188: Fix behavior of unparenthesized expressions will change in php v8
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Jan 16, 2020
1 parent c053a0a commit d2a9c15
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
33 changes: 17 additions & 16 deletions src/Blocks/ContentManager.php
Expand Up @@ -54,11 +54,11 @@ protected function setUse(string $path, bool $isTrait = false, bool $isLast = fa
* @param string $name
* @param null $extends
*/
protected function startClass(string $name, $extends = NULL): void
protected function startClass(string $name, $extends = null): void
{
$this->sourceCode .= PhpInterface::PHP_CLASS . PhpInterface::SPACE . $name
. PhpInterface::SPACE;
if ($extends !== NULL) {
if ($extends !== null) {
$this->sourceCode .=
PhpInterface::PHP_EXTENDS
. PhpInterface::SPACE . $extends . PhpInterface::SPACE;
Expand Down Expand Up @@ -163,7 +163,8 @@ protected function createProperty(
string $modifier,
$value = PhpInterface::PHP_TYPES_NULL,
bool $isString = false
): void {
): void
{
if ($value === PhpInterface::PHP_TYPES_NULL) { // drop null assignments as they are already nullable by default
$this->sourceCode .= PhpInterface::TAB_PSR4 . $modifier . PhpInterface::SPACE . PhpInterface::DOLLAR_SIGN .
$prop . PhpInterface::SEMICOLON . PHP_EOL;
Expand Down Expand Up @@ -362,17 +363,17 @@ public function closeRule(): void
}

/**
* @uses \SoliDry\Blocks\Controllers::setContent
* @uses \SoliDry\Blocks\Config::setContent
* @param string $basePath
* @param string $postFix
* @uses \SoliDry\Blocks\Migrations::setContent
* @uses \SoliDry\Blocks\Entities::setContent
* @uses \SoliDry\Blocks\FormRequest::setContent
* @uses \SoliDry\Blocks\Tests::setContent
*
* Creates entities like *Controller, *FormRequest, BaseModel entities etc
*
* @param string $basePath
* @param string $postFix
* @uses \SoliDry\Blocks\Controllers::setContent
* @uses \SoliDry\Blocks\Config::setContent
*/
public function createEntity(string $basePath, string $postFix = ''): void
{
Expand Down Expand Up @@ -457,7 +458,7 @@ public function quoteParam(string $param): string
protected function setBeforeProps(string $entityFile): void
{
$this->resourceCode = file_get_contents($entityFile);
$end = mb_strpos($this->resourceCode, DefaultInterface::PROPS_START, NULL, PhpInterface::ENCODING_UTF8) - 3;
$end = mb_strpos($this->resourceCode, DefaultInterface::PROPS_START, null, PhpInterface::ENCODING_UTF8) - 3;
$this->sourceCode = mb_substr($this->resourceCode, 0, $end, PhpInterface::ENCODING_UTF8);
}

Expand All @@ -466,14 +467,14 @@ protected function setBeforeProps(string $entityFile): void
*
* @param string $till
*/
protected function setAfterProps($till = NULL): void
protected function setAfterProps($till = null): void
{
$start = $this->setTabs() . mb_strpos($this->resourceCode, DefaultInterface::PROPS_END, NULL,
PhpInterface::ENCODING_UTF8) - 3;
if ($till === NULL) {
$this->sourceCode .= mb_substr($this->resourceCode, $start, NULL, PhpInterface::ENCODING_UTF8);
$start = $this->setTabs() . (mb_strpos($this->resourceCode, DefaultInterface::PROPS_END, null,
PhpInterface::ENCODING_UTF8) - 3);
if ($till === null) {
$this->sourceCode .= mb_substr($this->resourceCode, $start, null, PhpInterface::ENCODING_UTF8);
} else {
$end = mb_strpos($this->resourceCode, $till, NULL, PhpInterface::ENCODING_UTF8) - 3;
$end = mb_strpos($this->resourceCode, $till, null, PhpInterface::ENCODING_UTF8) - 3;
$this->sourceCode .= mb_substr($this->resourceCode, $start, $end - $start, PhpInterface::ENCODING_UTF8);
}
}
Expand All @@ -483,8 +484,8 @@ protected function setAfterProps($till = NULL): void
*/
private function setAfterMethods(): void
{
$start = mb_strpos($this->resourceCode, DefaultInterface::METHOD_END, NULL, PhpInterface::ENCODING_UTF8) - 3;
$this->sourceCode .= $this->setTabs() . mb_substr($this->resourceCode, $start, NULL,
$start = mb_strpos($this->resourceCode, DefaultInterface::METHOD_END, null, PhpInterface::ENCODING_UTF8) - 3;
$this->sourceCode .= $this->setTabs() . mb_substr($this->resourceCode, $start, null,
PhpInterface::ENCODING_UTF8);
}

Expand Down
34 changes: 17 additions & 17 deletions src/Blocks/EntitiesTrait.php
Expand Up @@ -47,7 +47,7 @@ trait EntitiesTrait
* @param string $object
* @return string
*/
public function getFormRequestEntity(string $version, string $object) : string
public function getFormRequestEntity(string $version, string $object): string
{
return DirsInterface::MODULES_DIR . PhpInterface::BACKSLASH . strtoupper($version) .
PhpInterface::BACKSLASH . DirsInterface::HTTP_DIR .
Expand All @@ -63,16 +63,16 @@ public function getFormRequestEntity(string $version, string $object) : string
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \ReflectionException
*/
protected function setEntities() : void
protected function setEntities(): void
{
$this->entity = Classes::cutEntity(Classes::getObjectName($this), DefaultInterface::CONTROLLER_POSTFIX);
$formRequestEntity = $this->getFormRequestEntity(conf::getModuleName(), $this->entity);
$this->entity = Classes::cutEntity(Classes::getObjectName($this), DefaultInterface::CONTROLLER_POSTFIX);
$formRequestEntity = $this->getFormRequestEntity(conf::getModuleName(), $this->entity);

$this->formRequest = new $formRequestEntity();
$this->props = get_object_vars($this->formRequest);
$this->props = get_object_vars($this->formRequest);

$this->modelEntity = Classes::getModelEntity($this->entity);
$this->model = new $this->modelEntity();
$this->model = new $this->modelEntity();

$container = Container::getInstance();
$this->response = $container->make(\SoliDry\Containers\Response::class);
Expand All @@ -88,12 +88,12 @@ protected function setEntities() : void
* @throws \InvalidArgumentException
* @throws \LogicException
*/
protected function saveBulk(Request $request) : Response
protected function saveBulk(Request $request): Response
{
$meta = [];
$meta = [];
$collection = new Collection();

$json = Json::decode($request->getContent());
$json = Json::decode($request->getContent());
$jsonApiAttributes = Json::getBulkAttributes($json);

try {
Expand Down Expand Up @@ -158,12 +158,12 @@ protected function saveBulk(Request $request) : Response
* @throws \SoliDry\Exceptions\AttributesException
* @throws \LogicException
*/
protected function mutateBulk(Request $request) : Response
protected function mutateBulk(Request $request): Response
{
$meta = [];
$meta = [];
$collection = new Collection();

$json = Json::decode($request->getContent());
$json = Json::decode($request->getContent());
$jsonApiAttributes = Json::getBulkAttributes($json);

try {
Expand Down Expand Up @@ -209,9 +209,9 @@ protected function mutateBulk(Request $request) : Response
* @return Response
* @throws \LogicException
*/
public function removeBulk(Request $request) : Response
public function removeBulk(Request $request): Response
{
$json = Json::decode($request->getContent());
$json = Json::decode($request->getContent());
$jsonApiAttributes = Json::getBulkAttributes($json);

try {
Expand Down Expand Up @@ -248,7 +248,7 @@ public function removeBulk(Request $request) : Response
private function getRelationType(string $objectName)
{
if (empty($this->generator->types[$objectName][ApiInterface::RAML_PROPS]
[ApiInterface::RAML_RELATIONSHIPS][ApiInterface::RAML_TYPE]) === false
[ApiInterface::RAML_RELATIONSHIPS][ApiInterface::RAML_TYPE]) === false
) {
return trim(
$this->generator->types[$objectName][ApiInterface::RAML_PROPS]
Expand All @@ -264,7 +264,7 @@ private function getRelationType(string $objectName)
*
* @throws \ReflectionException
*/
private function setUseSoftDelete() : void
private function setUseSoftDelete(): void
{
if ($this->isSoftDelete()) {
$this->setUse(Classes::getObjectName(SoftDeletes::class), true, true);
Expand All @@ -274,7 +274,7 @@ private function setUseSoftDelete() : void
/**
* Sets property for Soft Delete op on model Entity
*/
private function setPropSoftDelete() : void
private function setPropSoftDelete(): void
{
if ($this->isSoftDelete()) {
$this->createPropertyArray(ModelsInterface::PROPERTY_DATES, PhpInterface::PHP_MODIFIER_PROTECTED, [ModelsInterface::COLUMN_DEL_AT]);
Expand Down

0 comments on commit d2a9c15

Please sign in to comment.