2014年12月27日星期六

Community News: Packagist Latest Releases for 12.27.2014

Recent releases from the Packagist:

2014年12月26日星期五

Site News: Popular Posts for the Week of 12.26.2014

Popular posts from PHPDeveloper.org for the past week:

Community News: Packagist Latest Releases for 12.26.2014

Recent releases from the Packagist:

That Podcast: Episode 13: The one to cap 2014


That Podcast have posted their last episode of 2014, The one to cap 2014. Join hosts Beau Simensen and Dave Marshall as they talk about the happenings of 2014 and a wide variety of other topics.



Beau and Dave wrap up 2014 discussing a bunch of stuff. Dave was too excited about Christmas to write something more descriptive for this sentence. This one too.

Topics mentioned in the episode include:




...and many more. You can listen to this latest episode either through the in-page player or by downloading the mp3. If you enjoy the episode, be sure to subscribe to their feed too.


Link: http://thatpodcast.io/episodes/episode-13-the-one-to-cap-2014/

Nikita Popov: PHP's new hashtable implementation


In his latest post Nikita Popov gives a detailed look at PHP's new hashtable implementation and what kinds of improvements it offers over the previous methods. The "hashtable" handling is how the language references array values created during the execution of a script.



About three years ago I wrote an article analyzing the memory usage of arrays in PHP 5. As part of the work on the upcoming PHP 7, large parts of the Zend Engine have been rewritten with a focus on smaller data structures requiring fewer allocations. In this article I will provide an overview of the new hashtable implementation and show why it is more efficient than the previous implementation.


He starts with an introduction to the concept of hashtables, describing them as "ordered dictionaries" of key/value pairs that (internally) reference values in an array. He looks at the old method PHP used to make these links and how the new version, with the help of zval handling, is different. He talks about how it handles the order of elements, does lookups and the introduction of "packed" and "empty" hashtables. He ends the post with a look at this new implementation's memory utilization and what kind of performance gains we can expect with its introduction in PHP7.


Link: http://nikic.github.io/2014/12/22/PHPs-new-hashtable-implementation.html

Robert Basic: Mocking hard dependencies with Mockery


Robert Basic has a post today showing how you can mock hard dependencies with Mockery, a mocking library for use in unit testing. In this case, "hard" refers to work around the use of "new" creating objects in hard to test places.



One problem with unit testing legacy applications is that the code has new statements all over the place, instantiating new objects in a way that doesn't really makes it easier to test the code. Of course, the easy answer to this is "Just refactor your application!", but that's almost always easier said than done. If refactoring is an option, do it. If not, one option is to use Mockery to mock the hard dependencies.


He makes use of instance mocks to show the overloading of the service without the need for a refactor. This overrides it on a more global scale, so it could have an effect on other tests. He shows how autoloading and PHPUnit's own process isolation handling can fix tis problem (though it takes more time to run the tests this way). He includes sample code of the whole process so you can easily follow along too.


Link: http://robertbasic.com/blog/mocking-hard-dependencies-with-mockery

SitePoint PHP Blog: Visualize Your Code's Quality with PhpMetrics


The SitePoint PHP blog has a recent tutorial showing how to use PhpMetrics to visualize your application and the quality of its code.



We had been looking into code quality checking tools for a while here on SitePoint - most recently in a series on Jenkins, but none of those could do what a project I've only recently found out about can. PhpMetrics uses D3 and some sophisticated analysis algorithms to scan your application's code and output intricate reports about it.


He walks you through the install (via Composer) and how to clone two example projects, Laravel and Symfony, to evaluate. He includes the command line to run the evaluation and plenty of screenshots showing the results for things like:



  • Cyclomatic complexity
  • Abstractness
  • Maintainability
  • Code density


He uses the results from these two projects in his examples and, at the end of the post, summarizes and compares the results it produced.


Link: http://www.sitepoint.com/visualize-codes-quality-phpmetrics/