"There are only two hard things in Computer Science: cache invalidation and naming things." - Phil Karlton
De acordo com várias pesquisas através dos anos foi constatado que a grande maioria dos programadores passa a maior parte do tempo lendo código. Apesar de não ajudar muito a criar bom design, os nomes ajudam e muito a evitar a criação de design ruim e um exemplo disso é o foco do DDD na linguagem ubíqua. O motivo nem sempre é claro mas, vive no subconsciente já que eles nos ajudam a entender problemas, relações entre conceitos e na comunicação com as diferentes partes da empresa/ambiente de trabalho. O problema com os nomes é justamente achar um. E, como não existe uma fórmula mágica para acha-los vamos tentar achar alguns casos em que podemos melhorar um nome e destrinchar um processo, extremamente útil, para descoberta de nomes.
If your not using an ORM (object relational mapper) and are still writing SQL by hand, here's what you need to know.
An introduction into DBIx::Class and some of the concepts and goodies you should be aware off.
If your not using an ORM (object relational mapper) and are still writing SQL by hand, here's what you need to know.
An introduction into DBIx::Class and some of the concepts and goodies you should be aware off.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent. Workhorse Computing
Scalar::Util, List::Util, and List::MoreUtils provide simpler, cleaner, and faster solutions in XS for scalar introspection and list management than what is available in Pure Perl. This is a short introduction to the utilities and how they work with more recent Perl features like smart matching.
Perl, a cross-platform, open-source computer programming language used widely in the commercial and private computing sectors. Perl is a favourite among Web developers for its flexible, continually evolving text-processing and problem-solving capabilities.
CakePHP 3 comes with a new ORM. This talk starts with a short history of how this library came to be and then walk through a series of examples from beginner to advanced for using the Querying features of the ORM.
Some of the exercises we did during a week-long class on "Publishing and Using Linked Open Data" at the University of Maryland Digital Humanities Winter Institute.
From the Java Collections Framework to the enhancements Groovy brings to the table when working with Collections. Based on https://tedvinke.wordpress.com/?s=Groovy+Weekend+Collections
PHP 5.3 has many new features that allow very different paradigms of software development, that may be unfamiliar to many PHP developers. If you want to learn more about functional or aspect-oriented programming, or how to organize your PHP libraries according to the new de facto PHP namespacing standard, don't miss this talk.
Perl6 regular expression ("regex") syntax has a number of improvements over the Perl5 syntax. The inclusion of grammars as first-class entities in the language makes many uses of regexes clearer, simpler, and more maintainable. This talk looks at a few improvements in the regex syntax and also at how grammars can help make regex use cleaner and simpler.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent. Workhorse Computing
Scalar::Util, List::Util, and List::MoreUtils provide simpler, cleaner, and faster solutions in XS for scalar introspection and list management than what is available in Pure Perl. This is a short introduction to the utilities and how they work with more recent Perl features like smart matching.
Perl, a cross-platform, open-source computer programming language used widely in the commercial and private computing sectors. Perl is a favourite among Web developers for its flexible, continually evolving text-processing and problem-solving capabilities.
CakePHP 3 comes with a new ORM. This talk starts with a short history of how this library came to be and then walk through a series of examples from beginner to advanced for using the Querying features of the ORM.
Some of the exercises we did during a week-long class on "Publishing and Using Linked Open Data" at the University of Maryland Digital Humanities Winter Institute.
From the Java Collections Framework to the enhancements Groovy brings to the table when working with Collections. Based on https://tedvinke.wordpress.com/?s=Groovy+Weekend+Collections
PHP 5.3 has many new features that allow very different paradigms of software development, that may be unfamiliar to many PHP developers. If you want to learn more about functional or aspect-oriented programming, or how to organize your PHP libraries according to the new de facto PHP namespacing standard, don't miss this talk.
Perl6 regular expression ("regex") syntax has a number of improvements over the Perl5 syntax. The inclusion of grammars as first-class entities in the language makes many uses of regexes clearer, simpler, and more maintainable. This talk looks at a few improvements in the regex syntax and also at how grammars can help make regex use cleaner and simpler.
Array ============ 1. In array, elements can be accessed using .pdfanjaliselectionahd
Array:
============
1. In array, elements can be accessed using index/subscript value, i.e. elements can be randomly
accessed like arr[0], arr[3], etc. So array provides fast and random access.
2. Insertion & deletion takes more time in array as elements are stored in consecutive memory
locations.
3. In array, no pointers are used like linked list so no need of extra space in memory for pointer.
Linked List:
4. In array, elements are stored in consecutive manner in memory.
=============
1. In linked list, elements can’t be accessed randomly but can be accessed only sequentially and
accessing element takes 0(n) time.
2. Insertion & deletion are fast & easy in linked list as only value of pointer is needed to change.
3. In linked list, adjacency between the elements are maintained using pointers or links, so
pointers are used and for that extra memory space is needed.
4. In linked list, elements can be stored at any available place as address of node is stored in
previous node
/***********GroceryItem*************/
public class GroceryItem {
/*Instance variable declaration*/
private String name;
private int value;
/*Default constructor*/
public GroceryItem() {
super();
// TODO Auto-generated constructor stub
}
/*Parameterized constructor*/
public GroceryItem(String name, int value) {
super();
this.name = name;
this.value = value;
}
/*Getter and Mutators methods for each instance variable*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getValue() {
return value;
}
public void setValue(int value) {
if(value<0){
}
this.value = value;
}
/*ToString Method*/
@Override
public String toString() {
return \"GroceryItem [name=\" + name + \", value=\" + value + \"]\";
}
/*Equals method*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
GroceryItem other = (GroceryItem) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (value != other.value)
return false;
return true;
}
/*Equals Method*/
}
/**************GroceryList*******************/
public class GroceryList {
/* ListNode Class Declaration */
class ListNode {
GroceryItem data;
ListNode link;
/* Default constructor */
public ListNode() {
super();
// TODO Auto-generated constructor stub
}
/* Parameterized constructor */
public ListNode(GroceryItem data, ListNode link) {
super();
this.data = data;
this.link = link;
}
}
/* Instance variable declaration */
ListNode head;
ListNode current;
ListNode previous;
/* Default constructor and initialization of head,current,previous */
public GroceryList() {
super();
this.head = new ListNode();
this.current = head;
this.previous = head;
}
/* Method Implementations */
/* It will return next node */
public ListNode goToNext(ListNode temp) {
if (temp != null) {
temp = temp.link;
return temp;
}
return null;
}
/*
* It will return data from curren.
Once you have all the structures working as intended- it is time to co.docxfarrahkur54
Once you have all the structures working as intended, it is time to compare the
performances of the 2. Use runBenchmark() to start.
a. First, generate an increasing number (N) of random integers (1000, 5000, 10000,
50000, 75000, 100000, 500000 or as far as your computing power will let you)
i. Time and print how long it takes to insert the random integers into an initially
empty BST. Do not print the tree.
You can get a random list using the java class Random, located in
java.util.Random. To test the speed of the insertion algorithm, you should use
the System.currentTimeMillis() method, which returns a long that contains the
current time (in milliseconds). Call System.currentTimeMillis() before and after
the algorithm runs and subtract the two times. (Instant.now() is an alternative
way of recording the time.)
ii. Time and print how long it takes to insert the same random integers into an
initially empty AVL tree. Do not print the tree.
iii. If T(N) is the time function, how does the growth of TBST(N) compare with the
growth of TAVL(N)?
Plot a simple graph to of time against N for the two types of BSTs to visualize
your results.
b. Second, generate a list of k random integers. k is also some large value.
i. Time how long it takes to search your various N-node BSTs for all k random
integers. It does not matter whether the search succeeds.
ii. Time how long it takes to search your N-node AVL trees for the same k random
integers.
iii. Compare the growth rates of these two search time-functions with a graph the
same way you did in part a.
public class BinarySearchTree<AnyType extends Comparable<? super AnyType>> {
protected BinaryNode<AnyType> root;
public BinarySearchTree() {
root = null;
}
/**
* Insert into the tree; duplicates are ignored.
*
* @param x the item to insert.
* @param root
* @return
*/
protected BinaryNode<AnyType> insert(AnyType x, BinaryNode<AnyType> root) {
// If the root is null, we've reached an empty leaf node, so we create a new node
// with the value x and return it
if (root == null) {
return new BinaryNode<>(x, null, null);
}
// Compare the value of x to the value stored in the root node
int compareResult = x.compareTo(root.element);
// If x is less than the value stored in the root node, we insert it into the left subtree
if (compareResult < 0) {
root.left = insert(x, root.left);
}
// If x is greater than the value stored in the root node, we insert it into the right subtree
else if (compareResult > 0) {
root.right = insert(x, root.right);
}
// If x is equal to the value stored in the root node, we ignore it since the tree does not allow duplicates
return root;
}
/**
* Counts the number of leaf nodes in this tree.
*
* @param t The root of the tree.
* @return
*/
private int countLeafNodes(BinaryNode<AnyType> root) {
// If the root is null, it means the tree is empty, so we return 0
if (root == null) {
return 0;
}
// If the root has no children, it means it is a leaf node, so we return 1
if (root.left == .
Overview of the main ways to store data in Drupal 8 depending on data and needs. A detailed description of each way and examples of how to work with storages.
https://drupalcampkyiv.org/node/44
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdfarihantmobileselepun
(1)Objective: Binary Search Tree traversal (2 points)
Use traversal.pptx as guidance to write a program to build a binary search tree Dictionary. I of
BST have the same data from each input record.
Download traversal-lab.pptx, inventory.txt, BinNode.java, BSTNode.java, BST.java,
Dictionary.java .
Perform specifications as follow:
(a)Provide Add, Delete and Retrieve functions for user to access the database. Reject duplicate
record when add a new record.
(b)Modify BST.java to add printpostOrder, printpreOrder methods.
(c)At the end, display inorder, postorder and preorder of the tree.
Codes:
/** Source code example for \"A Practical Introduction to Data
Structures and Algorithm Analysis, 3rd Edition (Java)\"
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/
/** ADT for binary tree nodes */
public interface BinNode {
/** Get and set the element value */
public E element();
public void setElement(E v);
/** @return The left child */
public BinNode left();
/** @return The right child */
public BinNode right();
/** @return True if a leaf node, false otherwise */
public boolean isLeaf();
}
//********************************************************************
// StringTree.java
//
//********************************************************************
import java.util.*;
public class StringTree
{
private Node root;
//----------------------------------------------------------------
// Creates an initially empty tree.
//----------------------------------------------------------------
public StringTree()
{
root = null;
}
//----------------------------------------------------------------
// Adds a string to the tree.
//----------------------------------------------------------------
public void addString (String str)
{
root = addStringToSubTree(str, root);
}
//----------------------------------------------------------------
// Adds a string to the subtree with the given root node
//----------------------------------------------------------------
private Node addStringToSubTree (String str, Node node)
{
Node result = node;
if (node == null)
result = new Node(str);
// If the new string comes before the string in the node, add
// the new string to the left child. Otherwise, add it to the
// right child.
else
if (str.compareTo(node.value) < 0)
node.left = addStringToSubTree(str, node.left);
else
node.right = addStringToSubTree(str, node.right);
return result;
}
//----------------------------------------------------------------
// Prints the result of a depth-first traversal of the tree using
// recursion.
//----------------------------------------------------------------
public void traverseWithRecursion()
{
traverseWithRecursion(root);
}
//----------------------------------------------------------------
// Prints the elements in the specified tree using recursion.
//----------------------------------------------------------------
private void traverseWithRecursion (Node node)
{
if (node != null)
{
traverseWithRecursion (node.left);
System.
Como saber onde eu estou na carreira? Quais são as coisas que eu deveria investir e saber para ser considerado um desenvolvedor sênior ou para mudar de patamar? Como lidar com pessoas, dar feedback e receber feedback? E, mais importante como definir objetivos para que seu sonho se torne realidade.
Dívidas são algo cotidiano. Empresas e pessoas contraem dívidas para operar seus negócios ou realizar sonhos e, com código é a mesma coisa. Vez ou outra admitimos algo fora dos padrões de qualidade para corrigir algum problema ou ter alguma vantagem sobre a concorrência. O grande problema é quando essa nossa dívida sai do controle gerando prejuízos não só para a empresa mas, nós desenvolvedores.
A falta de controle dessa dívida tem como maior efeito software rígido, difícil de entender e mudar, tornando-o mais suscetível a bugs. Para pagar o que devemos, temos que reverter esse quadro aumentando a facilidade em entender o código. Como fazer isso? Usando bons nomes!
Palestra ministrada no TDC POA em 2016 sobre como usar esses dois princípios podem ajudar a melhorar seu código evitando alto acoplamento e problemas com referências nulas.
Palestra sobre os pilares que moldam e constroem a Programação Orientada a Objetos (OOP pros íntimos) além do conceito do que é um objeto e quais suas propriedades. A palestra ainda conta com uma relação de princípios e padrões de projeto que ajudam a detectar quebra de algum dos pilares do paradigma e como e quando utiliza-los.
Palestra sobre domínio que usa os conceitos definidos por Eric Evans (DDD) para explicar domínios e traçar um paralelo entre o Conway's law e a falta de domínio.
Apresentação sobre interfaces de objetos baseada no livro de Ken Pugh. Conceitos de o que é e quais são suas funções bem como algumas classificações para as mesmas que o autor achou interessante (com exemplos em PHP).
Palestra de TDD apresentada no InterconPHP no dia 19/07/2014.
A apresentação discorre rapidamente sobre conceitos básicos do Test Driven Development como:
- A diferença entre teste e teste automatizado;
- Os diferentes tipos de testes;
- O que é TDD;
- Explicação de um ciclo de TDD;
- E o porquê de usar TDD.
O repositório ao final da apresentação faz parte de uma demonstração de algumas iterações feitas pelos apresentadores para ilustrar os ciclos da prática.
Apresentação sobre TDD (Test Driven Development) ou Desenvolvimento Guiado por Testes feita no Hotel Urbano Tech Talks. A primeira parte da apresentação conta com uma introdução a metodologia, apresentação de seus principais conceitos e algumas práticas consideradas boas pelos autores. A segunda parte consiste em um live coding mostrando iterações para construir um aplicativo utilizando a escola britânica, que mescla TDD com ATDD.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteGoogle
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
✅Deploy AI expert bots in Any Niche With Just A Click
✅With one keyword, generate complete funnels, websites, landing pages, and more.
✅More than 85 AI features are included in the AI pilot.
✅No setup or configuration; use your voice (like Siri) to do whatever you want.
✅You Can Use AI Pilot To Create your version of AI Pilot And Charge People For It…
✅ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
✅ZERO Limits On Features Or Usages
✅Use Our AI-powered Traffic To Get Hundreds Of Customers
✅No Complicated Setup: Get Up And Running In 2 Minutes
✅99.99% Up-Time Guaranteed
✅30 Days Money-Back Guarantee
✅ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
top nidhi software solution freedownloadvrstrong314
This presentation emphasizes the importance of data security and legal compliance for Nidhi companies in India. It highlights how online Nidhi software solutions, like Vector Nidhi Software, offer advanced features tailored to these needs. Key aspects include encryption, access controls, and audit trails to ensure data security. The software complies with regulatory guidelines from the MCA and RBI and adheres to Nidhi Rules, 2014. With customizable, user-friendly interfaces and real-time features, these Nidhi software solutions enhance efficiency, support growth, and provide exceptional member services. The presentation concludes with contact information for further inquiries.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
Into the Box Keynote Day 2: Unveiling amazing updates and announcements for modern CFML developers! Get ready for exciting releases and updates on Ortus tools and products. Stay tuned for cutting-edge innovations designed to boost your productivity.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
Navigating the Metaverse: A Journey into Virtual Evolution"Donna Lenk
Join us for an exploration of the Metaverse's evolution, where innovation meets imagination. Discover new dimensions of virtual events, engage with thought-provoking discussions, and witness the transformative power of digital realms."
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
Keep tabs on your field staff effortlessly with Informap Technology Centre LLC. Real-time tracking, task assignment, and smart features for efficient management. Request a live demo today!
For more details, visit us : https://informapuae.com/field-staff-tracking/
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
Even though at surface level ‘java.lang.OutOfMemoryError’ appears as one single error; underlyingly there are 9 types of OutOfMemoryError. Each type of OutOfMemoryError has different causes, diagnosis approaches and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
Unlocking Business Potential: Tailored Technology Solutions by Prosigns
Discover how Prosigns, a leading technology solutions provider, partners with businesses to drive innovation and success. Our presentation showcases our comprehensive range of services, including custom software development, web and mobile app development, AI & ML solutions, blockchain integration, DevOps services, and Microsoft Dynamics 365 support.
Custom Software Development: Prosigns specializes in creating bespoke software solutions that cater to your unique business needs. Our team of experts works closely with you to understand your requirements and deliver tailor-made software that enhances efficiency and drives growth.
Web and Mobile App Development: From responsive websites to intuitive mobile applications, Prosigns develops cutting-edge solutions that engage users and deliver seamless experiences across devices.
AI & ML Solutions: Harnessing the power of Artificial Intelligence and Machine Learning, Prosigns provides smart solutions that automate processes, provide valuable insights, and drive informed decision-making.
Blockchain Integration: Prosigns offers comprehensive blockchain solutions, including development, integration, and consulting services, enabling businesses to leverage blockchain technology for enhanced security, transparency, and efficiency.
DevOps Services: Prosigns' DevOps services streamline development and operations processes, ensuring faster and more reliable software delivery through automation and continuous integration.
Microsoft Dynamics 365 Support: Prosigns provides comprehensive support and maintenance services for Microsoft Dynamics 365, ensuring your system is always up-to-date, secure, and running smoothly.
Learn how our collaborative approach and dedication to excellence help businesses achieve their goals and stay ahead in today's digital landscape. From concept to deployment, Prosigns is your trusted partner for transforming ideas into reality and unlocking the full potential of your business.
Join us on a journey of innovation and growth. Let's partner for success with Prosigns.
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
8. O processo de descoberta
Sem nome Sem sentido Honesto
Honesto e
Completo
Faz o que o
nome diz
Intenção
Abstração de
domínio
↪ ↪ ↪ ↪ ↪ ↪
9. O processo de descoberta
Sem nome Sem sentido Honesto
Honesto e
Completo
Faz o que o
nome diz
Intenção
Abstração de
domínio
↪ ↪ ↪ ↪ ↪ ↪
@arlobelshee
10. O processo de descoberta
Sem nome Sem sentido Honesto
Honesto e
Completo
Faz o que o
nome diz
Intenção
Abstração de
domínio
↪ ↪ ↪ ↪ ↪ ↪
@arlobelshee
Vamos até aqui!
11. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
Nosso código
↳
12. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
Assinatura
↳
13. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
Parâmetros booleanos…
14. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
15. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
Um loop com if, eh?
16. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
Sem nome!
17. private function getLists($iterator, $methodName, $exceptions, $skipHidden, $fullPath)
{
$dirs = $files = [];
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
return [$dirs, $files];
}
Nome sem sentido
↳
18. private function getLists($iterator, $methodName, $exceptions, $skipHidden, $fullPath)
{
$dirs = $files = [];
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
return [$dirs, $files];
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
Hmmm, um filtro!
19. private function getLists($iterator, $methodName, $exceptions, $skipHidden, $fullPath)
{
$dirs = $files = [];
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
return [$dirs, $files];
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
Cria uma lista de pastas e,
outra lista de arquivos
30. Características de bons nomes de métodos
•Use verbos;
•Sem abreviações;
•Conciso (mas, não muito!);
•Use perguntas quando o método retornar um boolean (isEmpty(), canDo());
•Não use “And” e “Or” nos seus nomes;
•Não deixe o nome redundante com o argumento
($list->addItem($item));
•Não deixe o nome redundante com quem chama
($list->addToList($item));
33. Bom nome?
•Use verbos √
•Sem abreviações √
•Conciso (mas, não muito!) √
•Use perguntas quando o método retornar um boolean (isEmpty(), canDo()) √
•Não use “And” e “Or” nos seus nomes √
•Não deixe o nome redundante com o argumento √
($list->addItem($item));
•Não deixe o nome redundante com quem chama √
($list->addToList($item));
40. private function iterateOverItemsToCreateSortableMapOfFilesAndDirsSkippingExceptions(
$iterator, $methodName, $exceptions, $skipHidden, $fullPath)
{
$dirs = $files = [];
foreach ($iterator as $item) {
if ($this->isFileRelevant($item, $skipHidden, $exceptions)) {
$name = $fullPath ? $item->getPathname() : $item->getFilename();
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
}
return [$dirs, $files];
}
Extrair comportamento pra
sua própria classe
41. Características de bons nomes de classes
•Use substantivos e adjetivos*;
•Não use muitos adjetivos (AbstractFactoryPatternBase);
•Não use “Manager”, “Helper” e “Data” nos seus nomes;
•Não use Sufixos do seu namespace (Service, Factory,
Iterator)
•Evite usar “er”, “or”, “tion”, “sion” (ObjectFinder,
DataProcessor, Conversion, DataManipulation)
53. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
Implementação
“rústica” de Set
54. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
Nome
“nonsense”
↳
55. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
Nome
“nonsense”
↳
Configuração em runtime?
Builder Pattern!
63. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
64. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
65. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
66. <?php
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
{
$dirs = $files = [];
if (!$this->pwd()) {
return [$dirs, $files];
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (Exception $e) {
return [$dirs, $files];
}
if (!is_bool($sort) && isset($this->_fsorts[$sort])) {
$methodName = $this->_fsorts[$sort];
} else {
$methodName = $this->_fsorts[self::SORT_NAME];
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFilename();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathname();
}
if ($item->isDir()) {
$dirs[$item->{$methodName}()][] = $name;
} else {
$files[$item->{$methodName}()][] = $name;
}
}
if ($sort || $this->sort) {
ksort($dirs);
ksort($files);
}
if ($dirs) {
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
}
/**
* Returns an array of the contents of the current directory.
* The returned array holds two arrays: One of directories and one of files.
*
* @param string|bool $sort Whether you want the results sorted, set this and the sort property
* to false to get unsorted results.
* @param array|bool $exceptions Either an array or boolean true will not grab dot files
* @param bool $fullPath True returns the full path
* @return array Contents of current directory as an array, an empty array on failure
*/
public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = false)
67. Concluindo…
1. Procure por lugares com mais de um nível de indentação
2. Extraia e dê nome para o que fizer sentido
3. Descreva o que o método realmente faz, sem vergonha, seja honesto!
4. Vá diminuindo o nome do método extraindo suas responsabilidades
5. Excesso de métodos privados para um dado contexto: Uma nova classe!
6. Procure na documentação ou fale com um amiguinho para descrever
o problema de domínio resolvido
7. Seja feliz!