Skip to content

Update bestseller.php#12847

Merged
danielkerr merged 1 commit intoopencart:masterfrom
TheCartpenter:patch-1350
Oct 29, 2023
Merged

Update bestseller.php#12847
danielkerr merged 1 commit intoopencart:masterfrom
TheCartpenter:patch-1350

Conversation

@TheCartpenter
Copy link
Copy Markdown
Contributor

No description provided.

@batumibiz
Copy link
Copy Markdown
Contributor

Why was type casting removed?
The method returns array

@TheCartpenter
Copy link
Copy Markdown
Contributor Author

Contributor

As per other models, we're not fetching the $results into a foreach . Therefore, the array does not need to be cast.

@batumibiz
Copy link
Copy Markdown
Contributor

As per other models, we're not fetching the $results into a foreach . Therefore, the array does not need to be cast.

What do other models have to do with it?
The current method returns an array.

  1. We are trying to get data (which is an array) from the cache.
  2. If there is no cached data, we make a request to the database and get the result in the form of an array.
  3. As a result, we must return an array.
  4. Since the cache->get() method returns mixed, it is very useful that we specify the type of data we receive.

As a result, type casting is useful here and there is no need to remove it.

@TheCartpenter
Copy link
Copy Markdown
Contributor Author

So are these models:

Each returns an array, they're not casted.

@batumibiz
Copy link
Copy Markdown
Contributor

So are these models:

Each returns an array, they're not casted.

Well, add casting there if you want to mess around.
Here the casting was done more correctly.

@TheCartpenter
Copy link
Copy Markdown
Contributor Author

So are these models:

Each returns an array, they're not casted.

Well, add casting there if you want to mess around. Here the casting was done more correctly.

By having a mixed parameter in the library, and based on the mount of results where $this->cache->get have more results without casting than those that are casted. I would rather wait and find out which part of the code's on the right track rather than knowing that only a few of them have been casted already.

@batumibiz
Copy link
Copy Markdown
Contributor

By having a mixed parameter in the library, and based on the mount of results where $this->cache->get have more results without casting than those that are casted. I would rather wait and find out which part of the code's on the right track rather than knowing that only a few of them have been casted already.

The method has a clearly specified return type - an array. And only an array cannot be anything else, it does not even have the right to be null, or false. bestseller.php#L14

@TheCartpenter
Copy link
Copy Markdown
Contributor Author

By having a mixed parameter in the library, and based on the mount of results where $this->cache->get have more results without casting than those that are casted. I would rather wait and find out which part of the code's on the right track rather than knowing that only a few of them have been casted already.

The method has a clearly specified return type - an array. And only an array cannot be anything else, it does not even have the right to be null, or false. bestseller.php#L14

Exactly. As you described on the above, since the output is only expected to be returned as an array, then there's no need to cast it.

@danielkerr danielkerr merged commit dfa9be8 into opencart:master Oct 29, 2023
@TheCartpenter TheCartpenter deleted the patch-1350 branch December 1, 2023 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants