1 cause it's shorter
I need your opinion about magical codes in Laravel
Here are 2 pieces of code that does the same thing. Which one do you prefer?
1- Magical:
$flights = App\Flight::where('active', 1)->first();
2- Unmagical:
$flights = App\Flight::query()->where('active', '=', 1)->first();
I personally like 2 because my IDE understands it.
Want to see more magic
//Flight.php
public function scopeActive(Builder $query) {
return $query->where('active',1);
}
// and then where ever whenever you want
$flights = App\Flight::active()->first();
by the way which IDE and should your IDE be limitation for your MAGICAL thresholds ?
@premsaurav I try not to use scopes.
Its personal opinion, but any specific reason ? With proper doc blocks any good ide should be able to understand the object returned.
@premsaurav I don't like to write a short code, just because it is short, then add some docblocks to help my IDE. Moreover, I don't like to consider App\Flight being a query builder as well. But as you say, it is personal opinion. And I just want to know the opinion of others. Thanks for your contribution to this discussion.
First option all the way. I'm not going to change the way I code to make an IDE happy.
Thanks @JeffreyWay I don't need my IDE to be happy at all. But when I write code in a way that it understand, it is going to help me more. For example in giving the list of parameters and static code analysis.
@halaei - You'll find that practically no one does your second example.
I would do:
$flights = Flight::where('active', true)->first();
Or even this one, if I'm feeling like Ms. Jackson.
$flights = Flight::active()->first(); // and then use a queryscope.
@JeffreyWay I agree that maybe no one does my way. But that can be because it is the way people learn Laravel not the way it is better.
Yeah, about that, if you could explain, why is the second approach BETTER ?
@premsaurav Just better to me, not better in general. And I don't think you can explain why it is not better at all.
@premsaurav for one thing, if you do code inspection using PhpStorm, you see the difference when inspection lists hundreds of false alarms just because of magic codes, because of which, you miss a couple of real positive alarms, once in a while.
I don't say that magic code is bad, but I prevent wiring one when it is easy not to do.
Yes, i can't and i won't. :( but just a verbose translation of the two ways
App\Flight::where('active', 1)->first();
// Hey flight, give me the first flight which is active
$flights = App\Flight::query()->where('active', '=', 1)->first();
// Hey flight, get hold of your underlying query builder, apply where `active` = 1 and then get me the first result.
I just feel, calling statement knows too much about the called method.
you see the difference when inspection lists hundreds of false alarms just because of magic codes.
This is where doc blocks helps. I am not trying to spam, but a file from a very popular library look like this
<?php
namespace Aws\Ec2;
use Aws\AwsClient;
use Aws\Api\Service;
use Aws\Api\DocModel;
use Aws\Api\ApiProvider;
/**
* Client used to interact with Amazon EC2.
*
* @method \Aws\Result acceptVpcPeeringConnection(array $args = [])
* @method \GuzzleHttp\Promise\Promise acceptVpcPeeringConnectionAsync(array $args = [])
* @method \Aws\Result allocateAddress(array $args = [])
* @method \GuzzleHttp\Promise\Promise allocateAddressAsync(array $args = [])
* @method \Aws\Result allocateHosts(array $args = [])
* @method \GuzzleHttp\Promise\Promise allocateHostsAsync(array $args = [])
* @method \Aws\Result assignPrivateIpAddresses(array $args = [])
* @method \GuzzleHttp\Promise\Promise assignPrivateIpAddressesAsync(array $args = [])
* @method \Aws\Result associateAddress(array $args = [])
* @method \GuzzleHttp\Promise\Promise associateAddressAsync(array $args = [])
* @method \Aws\Result associateDhcpOptions(array $args = [])
* @method \GuzzleHttp\Promise\Promise associateDhcpOptionsAsync(array $args = [])
* @method \Aws\Result associateRouteTable(array $args = [])
* @method \GuzzleHttp\Promise\Promise associateRouteTableAsync(array $args = [])
* @method \Aws\Result attachClassicLinkVpc(array $args = [])
* @method \GuzzleHttp\Promise\Promise attachClassicLinkVpcAsync(array $args = [])
* @method \Aws\Result attachInternetGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise attachInternetGatewayAsync(array $args = [])
* @method \Aws\Result attachNetworkInterface(array $args = [])
* @method \GuzzleHttp\Promise\Promise attachNetworkInterfaceAsync(array $args = [])
* @method \Aws\Result attachVolume(array $args = [])
* @method \GuzzleHttp\Promise\Promise attachVolumeAsync(array $args = [])
* @method \Aws\Result attachVpnGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise attachVpnGatewayAsync(array $args = [])
* @method \Aws\Result authorizeSecurityGroupEgress(array $args = [])
* @method \GuzzleHttp\Promise\Promise authorizeSecurityGroupEgressAsync(array $args = [])
* @method \Aws\Result authorizeSecurityGroupIngress(array $args = [])
* @method \GuzzleHttp\Promise\Promise authorizeSecurityGroupIngressAsync(array $args = [])
* @method \Aws\Result bundleInstance(array $args = [])
* @method \GuzzleHttp\Promise\Promise bundleInstanceAsync(array $args = [])
* @method \Aws\Result cancelBundleTask(array $args = [])
* @method \GuzzleHttp\Promise\Promise cancelBundleTaskAsync(array $args = [])
* @method \Aws\Result cancelConversionTask(array $args = [])
* @method \GuzzleHttp\Promise\Promise cancelConversionTaskAsync(array $args = [])
* @method \Aws\Result cancelExportTask(array $args = [])
* @method \GuzzleHttp\Promise\Promise cancelExportTaskAsync(array $args = [])
* @method \Aws\Result cancelImportTask(array $args = [])
* @method \GuzzleHttp\Promise\Promise cancelImportTaskAsync(array $args = [])
* @method \Aws\Result cancelReservedInstancesListing(array $args = [])
* @method \GuzzleHttp\Promise\Promise cancelReservedInstancesListingAsync(array $args = [])
* @method \Aws\Result cancelSpotFleetRequests(array $args = [])
* @method \GuzzleHttp\Promise\Promise cancelSpotFleetRequestsAsync(array $args = [])
* @method \Aws\Result cancelSpotInstanceRequests(array $args = [])
* @method \GuzzleHttp\Promise\Promise cancelSpotInstanceRequestsAsync(array $args = [])
* @method \Aws\Result confirmProductInstance(array $args = [])
* @method \GuzzleHttp\Promise\Promise confirmProductInstanceAsync(array $args = [])
* @method \Aws\Result copyImage(array $args = [])
* @method \GuzzleHttp\Promise\Promise copyImageAsync(array $args = [])
* @method \Aws\Result copySnapshot(array $args = [])
* @method \GuzzleHttp\Promise\Promise copySnapshotAsync(array $args = [])
* @method \Aws\Result createCustomerGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise createCustomerGatewayAsync(array $args = [])
* @method \Aws\Result createDhcpOptions(array $args = [])
* @method \GuzzleHttp\Promise\Promise createDhcpOptionsAsync(array $args = [])
* @method \Aws\Result createFlowLogs(array $args = [])
* @method \GuzzleHttp\Promise\Promise createFlowLogsAsync(array $args = [])
* @method \Aws\Result createImage(array $args = [])
* @method \GuzzleHttp\Promise\Promise createImageAsync(array $args = [])
* @method \Aws\Result createInstanceExportTask(array $args = [])
* @method \GuzzleHttp\Promise\Promise createInstanceExportTaskAsync(array $args = [])
* @method \Aws\Result createInternetGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise createInternetGatewayAsync(array $args = [])
* @method \Aws\Result createKeyPair(array $args = [])
* @method \GuzzleHttp\Promise\Promise createKeyPairAsync(array $args = [])
* @method \Aws\Result createNatGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise createNatGatewayAsync(array $args = [])
* @method \Aws\Result createNetworkAcl(array $args = [])
* @method \GuzzleHttp\Promise\Promise createNetworkAclAsync(array $args = [])
* @method \Aws\Result createNetworkAclEntry(array $args = [])
* @method \GuzzleHttp\Promise\Promise createNetworkAclEntryAsync(array $args = [])
* @method \Aws\Result createNetworkInterface(array $args = [])
* @method \GuzzleHttp\Promise\Promise createNetworkInterfaceAsync(array $args = [])
* @method \Aws\Result createPlacementGroup(array $args = [])
* @method \GuzzleHttp\Promise\Promise createPlacementGroupAsync(array $args = [])
* @method \Aws\Result createReservedInstancesListing(array $args = [])
* @method \GuzzleHttp\Promise\Promise createReservedInstancesListingAsync(array $args = [])
* @method \Aws\Result createRoute(array $args = [])
* @method \GuzzleHttp\Promise\Promise createRouteAsync(array $args = [])
* @method \Aws\Result createRouteTable(array $args = [])
* @method \GuzzleHttp\Promise\Promise createRouteTableAsync(array $args = [])
* @method \Aws\Result createSecurityGroup(array $args = [])
* @method \GuzzleHttp\Promise\Promise createSecurityGroupAsync(array $args = [])
* @method \Aws\Result createSnapshot(array $args = [])
* @method \GuzzleHttp\Promise\Promise createSnapshotAsync(array $args = [])
* @method \Aws\Result createSpotDatafeedSubscription(array $args = [])
* @method \GuzzleHttp\Promise\Promise createSpotDatafeedSubscriptionAsync(array $args = [])
* @method \Aws\Result createSubnet(array $args = [])
* @method \GuzzleHttp\Promise\Promise createSubnetAsync(array $args = [])
* @method \Aws\Result createTags(array $args = [])
* @method \GuzzleHttp\Promise\Promise createTagsAsync(array $args = [])
* @method \Aws\Result createVolume(array $args = [])
* @method \GuzzleHttp\Promise\Promise createVolumeAsync(array $args = [])
* @method \Aws\Result createVpc(array $args = [])
* @method \GuzzleHttp\Promise\Promise createVpcAsync(array $args = [])
* @method \Aws\Result createVpcEndpoint(array $args = [])
* @method \GuzzleHttp\Promise\Promise createVpcEndpointAsync(array $args = [])
* @method \Aws\Result createVpcPeeringConnection(array $args = [])
* @method \GuzzleHttp\Promise\Promise createVpcPeeringConnectionAsync(array $args = [])
* @method \Aws\Result createVpnConnection(array $args = [])
* @method \GuzzleHttp\Promise\Promise createVpnConnectionAsync(array $args = [])
* @method \Aws\Result createVpnConnectionRoute(array $args = [])
* @method \GuzzleHttp\Promise\Promise createVpnConnectionRouteAsync(array $args = [])
* @method \Aws\Result createVpnGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise createVpnGatewayAsync(array $args = [])
* @method \Aws\Result deleteCustomerGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteCustomerGatewayAsync(array $args = [])
* @method \Aws\Result deleteDhcpOptions(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteDhcpOptionsAsync(array $args = [])
* @method \Aws\Result deleteFlowLogs(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteFlowLogsAsync(array $args = [])
* @method \Aws\Result deleteInternetGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteInternetGatewayAsync(array $args = [])
* @method \Aws\Result deleteKeyPair(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteKeyPairAsync(array $args = [])
* @method \Aws\Result deleteNatGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteNatGatewayAsync(array $args = [])
* @method \Aws\Result deleteNetworkAcl(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteNetworkAclAsync(array $args = [])
* @method \Aws\Result deleteNetworkAclEntry(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteNetworkAclEntryAsync(array $args = [])
* @method \Aws\Result deleteNetworkInterface(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteNetworkInterfaceAsync(array $args = [])
* @method \Aws\Result deletePlacementGroup(array $args = [])
* @method \GuzzleHttp\Promise\Promise deletePlacementGroupAsync(array $args = [])
* @method \Aws\Result deleteRoute(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteRouteAsync(array $args = [])
* @method \Aws\Result deleteRouteTable(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteRouteTableAsync(array $args = [])
* @method \Aws\Result deleteSecurityGroup(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteSecurityGroupAsync(array $args = [])
* @method \Aws\Result deleteSnapshot(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteSnapshotAsync(array $args = [])
* @method \Aws\Result deleteSpotDatafeedSubscription(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteSpotDatafeedSubscriptionAsync(array $args = [])
* @method \Aws\Result deleteSubnet(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteSubnetAsync(array $args = [])
* @method \Aws\Result deleteTags(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteTagsAsync(array $args = [])
* @method \Aws\Result deleteVolume(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteVolumeAsync(array $args = [])
* @method \Aws\Result deleteVpc(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteVpcAsync(array $args = [])
* @method \Aws\Result deleteVpcEndpoints(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteVpcEndpointsAsync(array $args = [])
* @method \Aws\Result deleteVpcPeeringConnection(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteVpcPeeringConnectionAsync(array $args = [])
* @method \Aws\Result deleteVpnConnection(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteVpnConnectionAsync(array $args = [])
* @method \Aws\Result deleteVpnConnectionRoute(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteVpnConnectionRouteAsync(array $args = [])
* @method \Aws\Result deleteVpnGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteVpnGatewayAsync(array $args = [])
* @method \Aws\Result deregisterImage(array $args = [])
* @method \GuzzleHttp\Promise\Promise deregisterImageAsync(array $args = [])
* @method \Aws\Result describeAccountAttributes(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeAccountAttributesAsync(array $args = [])
* @method \Aws\Result describeAddresses(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeAddressesAsync(array $args = [])
* @method \Aws\Result describeAvailabilityZones(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeAvailabilityZonesAsync(array $args = [])
* @method \Aws\Result describeBundleTasks(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeBundleTasksAsync(array $args = [])
* @method \Aws\Result describeClassicLinkInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeClassicLinkInstancesAsync(array $args = [])
* @method \Aws\Result describeConversionTasks(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeConversionTasksAsync(array $args = [])
* @method \Aws\Result describeCustomerGateways(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeCustomerGatewaysAsync(array $args = [])
* @method \Aws\Result describeDhcpOptions(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeDhcpOptionsAsync(array $args = [])
* @method \Aws\Result describeExportTasks(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeExportTasksAsync(array $args = [])
* @method \Aws\Result describeFlowLogs(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeFlowLogsAsync(array $args = [])
* @method \Aws\Result describeHosts(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeHostsAsync(array $args = [])
* @method \Aws\Result describeIdFormat(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeIdFormatAsync(array $args = [])
* @method \Aws\Result describeImageAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeImageAttributeAsync(array $args = [])
* @method \Aws\Result describeImages(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeImagesAsync(array $args = [])
* @method \Aws\Result describeImportImageTasks(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeImportImageTasksAsync(array $args = [])
* @method \Aws\Result describeImportSnapshotTasks(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeImportSnapshotTasksAsync(array $args = [])
* @method \Aws\Result describeInstanceAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeInstanceAttributeAsync(array $args = [])
* @method \Aws\Result describeInstanceStatus(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeInstanceStatusAsync(array $args = [])
* @method \Aws\Result describeInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeInstancesAsync(array $args = [])
* @method \Aws\Result describeInternetGateways(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeInternetGatewaysAsync(array $args = [])
* @method \Aws\Result describeKeyPairs(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeKeyPairsAsync(array $args = [])
* @method \Aws\Result describeMovingAddresses(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeMovingAddressesAsync(array $args = [])
* @method \Aws\Result describeNatGateways(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeNatGatewaysAsync(array $args = [])
* @method \Aws\Result describeNetworkAcls(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeNetworkAclsAsync(array $args = [])
* @method \Aws\Result describeNetworkInterfaceAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeNetworkInterfaceAttributeAsync(array $args = [])
* @method \Aws\Result describeNetworkInterfaces(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeNetworkInterfacesAsync(array $args = [])
* @method \Aws\Result describePlacementGroups(array $args = [])
* @method \GuzzleHttp\Promise\Promise describePlacementGroupsAsync(array $args = [])
* @method \Aws\Result describePrefixLists(array $args = [])
* @method \GuzzleHttp\Promise\Promise describePrefixListsAsync(array $args = [])
* @method \Aws\Result describeRegions(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeRegionsAsync(array $args = [])
* @method \Aws\Result describeReservedInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeReservedInstancesAsync(array $args = [])
* @method \Aws\Result describeReservedInstancesListings(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeReservedInstancesListingsAsync(array $args = [])
* @method \Aws\Result describeReservedInstancesModifications(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeReservedInstancesModificationsAsync(array $args = [])
* @method \Aws\Result describeReservedInstancesOfferings(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeReservedInstancesOfferingsAsync(array $args = [])
* @method \Aws\Result describeRouteTables(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeRouteTablesAsync(array $args = [])
* @method \Aws\Result describeScheduledInstanceAvailability(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeScheduledInstanceAvailabilityAsync(array $args = [])
* @method \Aws\Result describeScheduledInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeScheduledInstancesAsync(array $args = [])
* @method \Aws\Result describeSecurityGroups(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeSecurityGroupsAsync(array $args = [])
* @method \Aws\Result describeSnapshotAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeSnapshotAttributeAsync(array $args = [])
* @method \Aws\Result describeSnapshots(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeSnapshotsAsync(array $args = [])
* @method \Aws\Result describeSpotDatafeedSubscription(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeSpotDatafeedSubscriptionAsync(array $args = [])
* @method \Aws\Result describeSpotFleetInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeSpotFleetInstancesAsync(array $args = [])
* @method \Aws\Result describeSpotFleetRequestHistory(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeSpotFleetRequestHistoryAsync(array $args = [])
* @method \Aws\Result describeSpotFleetRequests(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeSpotFleetRequestsAsync(array $args = [])
* @method \Aws\Result describeSpotInstanceRequests(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeSpotInstanceRequestsAsync(array $args = [])
* @method \Aws\Result describeSpotPriceHistory(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeSpotPriceHistoryAsync(array $args = [])
* @method \Aws\Result describeSubnets(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeSubnetsAsync(array $args = [])
* @method \Aws\Result describeTags(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeTagsAsync(array $args = [])
* @method \Aws\Result describeVolumeAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVolumeAttributeAsync(array $args = [])
* @method \Aws\Result describeVolumeStatus(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVolumeStatusAsync(array $args = [])
* @method \Aws\Result describeVolumes(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVolumesAsync(array $args = [])
* @method \Aws\Result describeVpcAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVpcAttributeAsync(array $args = [])
* @method \Aws\Result describeVpcClassicLink(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVpcClassicLinkAsync(array $args = [])
* @method \Aws\Result describeVpcClassicLinkDnsSupport(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVpcClassicLinkDnsSupportAsync(array $args = [])
* @method \Aws\Result describeVpcEndpointServices(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVpcEndpointServicesAsync(array $args = [])
* @method \Aws\Result describeVpcEndpoints(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVpcEndpointsAsync(array $args = [])
* @method \Aws\Result describeVpcPeeringConnections(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVpcPeeringConnectionsAsync(array $args = [])
* @method \Aws\Result describeVpcs(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVpcsAsync(array $args = [])
* @method \Aws\Result describeVpnConnections(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVpnConnectionsAsync(array $args = [])
* @method \Aws\Result describeVpnGateways(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeVpnGatewaysAsync(array $args = [])
* @method \Aws\Result detachClassicLinkVpc(array $args = [])
* @method \GuzzleHttp\Promise\Promise detachClassicLinkVpcAsync(array $args = [])
* @method \Aws\Result detachInternetGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise detachInternetGatewayAsync(array $args = [])
* @method \Aws\Result detachNetworkInterface(array $args = [])
* @method \GuzzleHttp\Promise\Promise detachNetworkInterfaceAsync(array $args = [])
* @method \Aws\Result detachVolume(array $args = [])
* @method \GuzzleHttp\Promise\Promise detachVolumeAsync(array $args = [])
* @method \Aws\Result detachVpnGateway(array $args = [])
* @method \GuzzleHttp\Promise\Promise detachVpnGatewayAsync(array $args = [])
* @method \Aws\Result disableVgwRoutePropagation(array $args = [])
* @method \GuzzleHttp\Promise\Promise disableVgwRoutePropagationAsync(array $args = [])
* @method \Aws\Result disableVpcClassicLink(array $args = [])
* @method \GuzzleHttp\Promise\Promise disableVpcClassicLinkAsync(array $args = [])
* @method \Aws\Result disableVpcClassicLinkDnsSupport(array $args = [])
* @method \GuzzleHttp\Promise\Promise disableVpcClassicLinkDnsSupportAsync(array $args = [])
* @method \Aws\Result disassociateAddress(array $args = [])
* @method \GuzzleHttp\Promise\Promise disassociateAddressAsync(array $args = [])
* @method \Aws\Result disassociateRouteTable(array $args = [])
* @method \GuzzleHttp\Promise\Promise disassociateRouteTableAsync(array $args = [])
* @method \Aws\Result enableVgwRoutePropagation(array $args = [])
* @method \GuzzleHttp\Promise\Promise enableVgwRoutePropagationAsync(array $args = [])
* @method \Aws\Result enableVolumeIO(array $args = [])
* @method \GuzzleHttp\Promise\Promise enableVolumeIOAsync(array $args = [])
* @method \Aws\Result enableVpcClassicLink(array $args = [])
* @method \GuzzleHttp\Promise\Promise enableVpcClassicLinkAsync(array $args = [])
* @method \Aws\Result enableVpcClassicLinkDnsSupport(array $args = [])
* @method \GuzzleHttp\Promise\Promise enableVpcClassicLinkDnsSupportAsync(array $args = [])
* @method \Aws\Result getConsoleOutput(array $args = [])
* @method \GuzzleHttp\Promise\Promise getConsoleOutputAsync(array $args = [])
* @method \Aws\Result getPasswordData(array $args = [])
* @method \GuzzleHttp\Promise\Promise getPasswordDataAsync(array $args = [])
* @method \Aws\Result importImage(array $args = [])
* @method \GuzzleHttp\Promise\Promise importImageAsync(array $args = [])
* @method \Aws\Result importInstance(array $args = [])
* @method \GuzzleHttp\Promise\Promise importInstanceAsync(array $args = [])
* @method \Aws\Result importKeyPair(array $args = [])
* @method \GuzzleHttp\Promise\Promise importKeyPairAsync(array $args = [])
* @method \Aws\Result importSnapshot(array $args = [])
* @method \GuzzleHttp\Promise\Promise importSnapshotAsync(array $args = [])
* @method \Aws\Result importVolume(array $args = [])
* @method \GuzzleHttp\Promise\Promise importVolumeAsync(array $args = [])
* @method \Aws\Result modifyHosts(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifyHostsAsync(array $args = [])
* @method \Aws\Result modifyIdFormat(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifyIdFormatAsync(array $args = [])
* @method \Aws\Result modifyImageAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifyImageAttributeAsync(array $args = [])
* @method \Aws\Result modifyInstanceAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifyInstanceAttributeAsync(array $args = [])
* @method \Aws\Result modifyInstancePlacement(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifyInstancePlacementAsync(array $args = [])
* @method \Aws\Result modifyNetworkInterfaceAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifyNetworkInterfaceAttributeAsync(array $args = [])
* @method \Aws\Result modifyReservedInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifyReservedInstancesAsync(array $args = [])
* @method \Aws\Result modifySnapshotAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifySnapshotAttributeAsync(array $args = [])
* @method \Aws\Result modifySpotFleetRequest(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifySpotFleetRequestAsync(array $args = [])
* @method \Aws\Result modifySubnetAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifySubnetAttributeAsync(array $args = [])
* @method \Aws\Result modifyVolumeAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifyVolumeAttributeAsync(array $args = [])
* @method \Aws\Result modifyVpcAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifyVpcAttributeAsync(array $args = [])
* @method \Aws\Result modifyVpcEndpoint(array $args = [])
* @method \GuzzleHttp\Promise\Promise modifyVpcEndpointAsync(array $args = [])
* @method \Aws\Result monitorInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise monitorInstancesAsync(array $args = [])
* @method \Aws\Result moveAddressToVpc(array $args = [])
* @method \GuzzleHttp\Promise\Promise moveAddressToVpcAsync(array $args = [])
* @method \Aws\Result purchaseReservedInstancesOffering(array $args = [])
* @method \GuzzleHttp\Promise\Promise purchaseReservedInstancesOfferingAsync(array $args = [])
* @method \Aws\Result purchaseScheduledInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise purchaseScheduledInstancesAsync(array $args = [])
* @method \Aws\Result rebootInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise rebootInstancesAsync(array $args = [])
* @method \Aws\Result registerImage(array $args = [])
* @method \GuzzleHttp\Promise\Promise registerImageAsync(array $args = [])
* @method \Aws\Result rejectVpcPeeringConnection(array $args = [])
* @method \GuzzleHttp\Promise\Promise rejectVpcPeeringConnectionAsync(array $args = [])
* @method \Aws\Result releaseAddress(array $args = [])
* @method \GuzzleHttp\Promise\Promise releaseAddressAsync(array $args = [])
* @method \Aws\Result releaseHosts(array $args = [])
* @method \GuzzleHttp\Promise\Promise releaseHostsAsync(array $args = [])
* @method \Aws\Result replaceNetworkAclAssociation(array $args = [])
* @method \GuzzleHttp\Promise\Promise replaceNetworkAclAssociationAsync(array $args = [])
* @method \Aws\Result replaceNetworkAclEntry(array $args = [])
* @method \GuzzleHttp\Promise\Promise replaceNetworkAclEntryAsync(array $args = [])
* @method \Aws\Result replaceRoute(array $args = [])
* @method \GuzzleHttp\Promise\Promise replaceRouteAsync(array $args = [])
* @method \Aws\Result replaceRouteTableAssociation(array $args = [])
* @method \GuzzleHttp\Promise\Promise replaceRouteTableAssociationAsync(array $args = [])
* @method \Aws\Result reportInstanceStatus(array $args = [])
* @method \GuzzleHttp\Promise\Promise reportInstanceStatusAsync(array $args = [])
* @method \Aws\Result requestSpotFleet(array $args = [])
* @method \GuzzleHttp\Promise\Promise requestSpotFleetAsync(array $args = [])
* @method \Aws\Result requestSpotInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise requestSpotInstancesAsync(array $args = [])
* @method \Aws\Result resetImageAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise resetImageAttributeAsync(array $args = [])
* @method \Aws\Result resetInstanceAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise resetInstanceAttributeAsync(array $args = [])
* @method \Aws\Result resetNetworkInterfaceAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise resetNetworkInterfaceAttributeAsync(array $args = [])
* @method \Aws\Result resetSnapshotAttribute(array $args = [])
* @method \GuzzleHttp\Promise\Promise resetSnapshotAttributeAsync(array $args = [])
* @method \Aws\Result restoreAddressToClassic(array $args = [])
* @method \GuzzleHttp\Promise\Promise restoreAddressToClassicAsync(array $args = [])
* @method \Aws\Result revokeSecurityGroupEgress(array $args = [])
* @method \GuzzleHttp\Promise\Promise revokeSecurityGroupEgressAsync(array $args = [])
* @method \Aws\Result revokeSecurityGroupIngress(array $args = [])
* @method \GuzzleHttp\Promise\Promise revokeSecurityGroupIngressAsync(array $args = [])
* @method \Aws\Result runInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise runInstancesAsync(array $args = [])
* @method \Aws\Result runScheduledInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise runScheduledInstancesAsync(array $args = [])
* @method \Aws\Result startInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise startInstancesAsync(array $args = [])
* @method \Aws\Result stopInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise stopInstancesAsync(array $args = [])
* @method \Aws\Result terminateInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise terminateInstancesAsync(array $args = [])
* @method \Aws\Result unassignPrivateIpAddresses(array $args = [])
* @method \GuzzleHttp\Promise\Promise unassignPrivateIpAddressesAsync(array $args = [])
* @method \Aws\Result unmonitorInstances(array $args = [])
* @method \GuzzleHttp\Promise\Promise unmonitorInstancesAsync(array $args = [])
*/
class Ec2Client extends AwsClient
{
public function __construct(array $args)
{
$args['with_resolved'] = function (array $args) {
$this->getHandlerList()->appendInit(
CopySnapshotMiddleware::wrap(
$this,
$args['endpoint_provider']
),
'ec2.copy_snapshot'
);
};
parent::__construct($args);
}
/**
* @internal
* @codeCoverageIgnore
*/
public static function applyDocFilters(array $api, array $docs)
{
// Several copy snapshot parameters are optional.
$docs['shapes']['String']['refs']['CopySnapshotRequest$PresignedUrl']
= '<div class="alert alert-info">The SDK will compute this value '
. 'for you on your behalf.</div>';
$docs['shapes']['String']['refs']['CopySnapshotRequest$DestinationRegion']
= '<div class="alert alert-info">The SDK will populate this '
. 'parameter on your behalf using the configured region value of '
. 'the client.</div>';
return [
new Service($api, ApiProvider::defaultProvider()),
new DocModel($docs)
];
}
}
@premsaurav Is this really that much complicated?
// Hey flight, get hold of your underlying query builder, apply where active = 1 and then get me the first result.
@premsaurav So Amazon ships classes with magic methods getting documented, but Laravel lets you do that yourself, once per SQL table.
Anyway, I feel I now get what @premsaurav says. I guess it is a good approach too:
- Write shorter code, so that the eye can read it better.
- Use PHPDocs to help your IDE in a place that you are not going to look at very often.
But I guess it is slightly more code than just not using magic code, in some cases.
Yes, its that complicated, even with one , behind the scene, almost second will be executed, but with the difference that, you don't have to worry about.
About doc blocks, yes you will have to do that, no escape :-/, after all its a framework
If your methods are well named and explicit, then I don't see why Flight::active()->first(); would be less preferable.
Programming is about getting things done and achieving client/business goals. Remember, most of the time, the client will never see your code.
Thanks @deringer for your reply.
I don't exactly know why my code style is different from those who have kindly replied. But, maybe that is the way I started to use Laravel. It was the first time I wrote code in PHP, and I began doing it professionally and for a serious project. When I see a code like Flight::active()->first(); and I did not understand, to figure it out I searched for the function active(), and when it was not there, it was more confusing than helpful. I also was confused how a class that represents a row of a table should have code inside it to query the database and still the code is extremely popular in the community. After further investigation I find out about how magic methods work and the fact that query methods are not actually inside the model class.
So I am biased toward a code that IDE understand easier, or a C++ programmer can begin to maintain and develop as soon as possible, even though he knows a little about PHP.
It's interesting you say you couldn't find the active method documented, yet found your way to the query method, which isn't documented in the docs on the Laravel site, either.
Eloquent implements the ActiveRecord pattern; it does loads of stuff that might be considered to violate some SOLID principles but as DHH says; it's so fucking convenient ;)
When you start using \Flight you should know you're working with the model and it shouldn't take you that long to find a scopeActive() function in the model's code.. even though it's not litterally the active() function as using in the controller. I can't believe that I would have missed the scope-documentation if I didn't read about it even before I started.
I started learning Laravel from the docs, then Laracasts and then I started programming myself. The scopes are just a way of programming that Laravel teaches you along the way. Why should your IDE know about this... every framework and code has it's learning curve. If it was all that easy, everybody would be a programmer.
Besides, looking at your comments I doubt that you are ever going to change your mind about this issue, since you persist on pushing your thoughts to the community more than adopting any of the comments posted by others. It's clear where you stand, but it looks like you're in a lonely place on this one.
@deringer I like to dog into code more than to read docs. ;)
You might have saved yourself some time if you read the docs, though!
@Pendo Thanks. I guess I am lonely ;)
@deringer I read the docs, then I find it weired, because I want to know what is under the hood. Then looked at the code, and it started to make sense more. You did that too, didn't you?
@halaei for sure, but the docs cover more than enough to get going. They also certainly cover query scopes.
Digging into the underlying code is great, too, but the big selling point for the framework is its ease of use and that's covered quite comprehensively in the docs. If there's anything missing, submit a PR against the docs repo.
Please or to participate in this conversation.