This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Invoice { | |
public int $id; | |
// The external identifier is never an essential | |
// responsibilty for an object | |
public string $customerName; | |
public array $items; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// package.json | |
{ | |
"name": "my-app", | |
"dependencies": { | |
"react": "18.2.0", | |
"lodash": "4.17.21", // Correct spelling with exact version | |
"@company-scope/internal-logger": "2.1.0" // Scoped package | |
}, | |
"resolutions": { | |
"lodash": "4.17.21" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// package.json | |
{ | |
"name": "my-app", | |
"dependencies": { | |
"react": "^18.2.0", | |
"lodahs": "1.0.0", // Typosquatting attack | |
"internal-logger": "2.1.0" | |
// Vulnerable to dependency confusion | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TVSeriesTest { | |
// No shared setup | |
@Test | |
public void testRecommendation() { | |
// Create only what's needed for this specific test | |
// And move this test with the behavior | |
TVSeries theEternaut = createTheEternautSeries(); | |
User homer = createUserWithPreferences(); | |
addReviewsForUser(theEternaut, homer); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TVSeriesTest { | |
private MovieSeries theEternaut; | |
private List<Character> characters; | |
private List<Episode> episodes; | |
private User user; | |
private UserPreferences preferences; | |
private RatingSystem ratingSystem; | |
private StreamingService streamingService; | |
private List<Review> reviews; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class WallpaperInitializer | |
{ | |
private static bool wallpaperWasDefined = false; | |
public static void InitializeWallpaper() | |
{ | |
if (wallpaperWasDefined) | |
{ | |
LoadWallpaperBitmap(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class WallpaperInitializer | |
{ | |
private static bool wallpaperWasDefined = false; | |
public static void InitializeWallpaper() | |
{ | |
if (wallpaperWasDefined) | |
// Assume this was defined previously | |
// and PLEASE DON'T use NULLs in case you hadn't | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isNotNull(x) { | |
return x !== null && x !== undefined | |
// Another code smell here | |
} | |
function mapToValueAndMeta(y) { | |
const meta = y.meta ? y.meta : { default: true } | |
return { val: y.value, meta } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const result = arr.filter(x => x !== null && x !== undefined) | |
.map((y) => ({ val: y.value, meta: | |
y.meta ? y.meta : {default: true}})) | |
.reduce((acc, {val, meta}) => | |
meta.default ? acc : [...acc, | |
{processed: val * 2, origin: meta}], []) | |
.some(({processed}) => processed > 10 && processed < 50); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[](){} | |
/* This valid lambda function: | |
Captures no variables. | |
Takes no arguments. | |
Performs no actions. | |
[]: This is the capture clause. | |
It specifies which variables from the surrounding scope |